如何将句子(字符串)中的单词更改为标题案例,该句子中的连词应留在或更改为较低字母
我需要知道如何将句子(字符串)中的单词更改为标题案例,句子中的连词必须保留或更改为较低字母(所有单词)。
类似于str_to_title(句子,locale =“ en”)
,从字符串库中,但该函数识别连词(for和the,from等)。 最常见的协调连词是:对于,也是,或者,或者,或者如此。
同样,重要的是, 一词保持较低的情况,而不是第一个单词。第一个和遗言应始终在上案中具有首字母。
例如:
sentence = "THE LOVer Tells OF THE rose in HIS HEART"
我希望字符串句子更改为:
"The Lover Tells of the Rose in His Heart"
称为a 标题案例。
任何帮助都将受到赞赏
I need to know how to change the words in a sentence (string) to Title Case, where the conjunctions in the sentence have to stay or change to lower letters (all the word).
Something similar to str_to_title(sentence, locale = "en")
, from the string library, but in which the function recognizes conjunctions (for, and, the, from, etc.).
The most common coordinating conjunctions are: for, and, nor, but, or, yet, and so.
Also, it is important that the word the stay as lower case but not when is the first word. The first and last words should always have the first letter in upper case.
For example:
sentence = "THE LOVer Tells OF THE rose in HIS HEART"
I want the string sentence to change to:
"The Lover Tells of the Rose in His Heart"
Which is called a Title Case.
Any help is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该解决方案怎么样?
我从编程中弄清楚了您的问题。
Tolower
。str_to_title
。粘贴
单词中的句子。结果
将是[1]“爱人在他心中讲述玫瑰”
How about this solution?
I figured your question out of programming.
tolower
.str_to_title
.paste
the words into a sentence.The
result
would be[1] "The Lover Tells of the Rose in His Heart"
使用
Library(工具)加载软件包
,使用TotitleCase函数转换您的字符串TotitleCase(句子)
,并且完成了!请注意,此功能仅适用于英语,而不适用于其他任何语言。Load the package using
library(tools)
, use the toTitleCase function to convert your stringtoTitleCase(sentence)
and it's done! Just be mindful that this function only works for English, not any other languages.