r - 如何将字符串向量的最后一个字符大写?
问题描述
我刚开始使用 R,我想知道如何创建一个将字符串向量的最后一个字符大写的函数。
解决方案
基础 R 正则表达式:
words <- c("hello", "world")
# Last character of last word in vec element:
gsub("(\\w$)", "\\U\\1", words, perl = TRUE)
sentences <- c("hello world", "hello friend")
# Last character of sentence:
gsub("(\\w$)", "\\U\\1", sentences, perl = TRUE)
# Last character of each word in the sentence:
gsub("(\\w\\s+|\\w$)", "\\U\\1", sentences, perl = TRUE)
推荐阅读
- php - 如何在 php 中的 post 中找到 hashtag 和 tag 和 url?
- react-native - AutoHeightWebView 的 React-native Display 导致 Android 10 和 Android 11 崩溃
- javascript - JavaScript - 我想显示一个指示用户等待进程完成的模式
- css - 是否有任何库支持放大/缩小角度 10+ 的角度 div 或文本或图像
- c - 我的代码有什么问题我无法在 vscode 中使用 scanf
- r - 为什么这个产品不产生 pi 的值?
- facebook-graph-api - Facebook Graph API - ID 匹配 API 是否适用于合作伙伴?
- nginx - NGINX - 使用 JWT 保护资源
- php - 通过 JWT Token 识别用户?
- android - 该应用程序可以正常工作,但是在构建某些小部件时不会出现flutter dart android