mysql中转换成字符串
Hello, folks. In this tutorial we are going to convert the case of the string in R. The R language offers functions such as tolower(), toupper(), and casefold() to convert the case of the given string from upper to lower or vice versa as well.
大家好 在本教程中,我们将转换R中字符串的大小写。R语言提供了诸如tolower(),toupper()和casefold()之类的函数,用于将给定字符串的大小写从大写转换为小写,反之亦然也一样
Let’s see how these functions work.
让我们看看这些功能是如何工作的。
R中用于大小写转换的函数 (Functions used for case conversion in R)
tolower() = The tolower() function is used to convert the string characters to the lower case.
tolower()= tolower()函数用于将字符串字符转换为小写。
toupper() = The toupper() function is used to convert the string characters to upper case.
toupper()= toupper()函数用于将字符串字符转换为大写。
casefold() = The casefold function is used to convert the string characters from lower to upper case and vice versa as well.
casefold() = casefold函数用于将字符串字符从小写转换为大写,反之亦然。
让我们从语法开始 (Let’s start with the syntax)
- The syntax of the function tolower() is, 函数tolower()的语法是,
tolower(x)
x = string or a character vector
x =字符串或字符向量
- The syntax of the toupper() function is, toupper()函数的语法是,
toupper(x)
x = string or a character vector
x =字符串或字符向量
使用tolower()函数将字符串转换为小写 (Convert a string to lower case using tolower() function)
In this section, we are going to convert a string or a character vector to a lower case using tolower() function.
在本节中,我们将使用tolower()函数将字符串或字符向量转换为小写。
tolower("WWW.JOURNALDEV.COM")
Output = “www.journaldev.com”
输出=“ www.journaldev.com”
df<-c("HAVE A GOOD DAY")
tolower(df)
Output = “have a good day”
输出=“祝你有美好的一天”
The tolower() function will convert the case of the characters to lower as shown above.
tolower()函数将把字符的大小写转换为小写,如上所示。
Now, let’s convert the case of the characters present in a data set ‘state.division’.
现在,让我们转换数据集“ state.division”中存在的字符的大小写 。
![Lower In R](https://i-blog.csdnimg.cn/blog_migrate/b13e52ba119a41974a6246de533b196a.png)
Let’s see how tolower() function converts the case of the string to lower case.
让我们看看tolower()函数如何将字符串的大小写转换为小写。
tolower(state.division)
![Lower](https://i-blog.csdnimg.cn/blog_migrate/eb196addcd97c5716e18043e75b57fdd.png)
In the above output you can see that all the strings present in the column species get converted into small letters or lower cases.
在上面的输出中,您可以看到列种类中存在的所有字符串都转换为小写字母或小写字母。
使用toupper()函数将字符串转换为大写 (Convert a string to upper case using toupper() function)
In the above sections we have converted the strings to lower case. Now let’s convert the strings to upper case using toupper() function in R.
在以上各节中,我们已将字符串转换为小写。 现在,让我们使用R中的toupper()函数将字符串转换为大写。
toupper("www.journaldev.com")
Output = “WWW.JOURNALDEV.COM”
输出=“ WWW.JOURNALDEV.COM”
toupper("have a good day")
Output = “HAVE A GOOD DAY”
输出=“祝你有美好的一天”
These are just a few examples of the toupper() function. It converts the lower case string characters to upper case in R.
这些只是toupper()函数的几个示例。 它将R中的小写字符串转换为大写。
Let’s convert the string characters of a data frame to the upper case using toupper() function in R.
让我们使用R中的toupper()函数将数据帧的字符串字符转换为大写。
![Toupper In R 1 1](https://i-blog.csdnimg.cn/blog_migrate/4c943a97b3434ebf381e9b5a53bbfcab.png)
toupper(state.region)
In the below output you can see how toupper() function converts the string characters of the data frame to upper case.
在下面的输出中,您可以看到toupper()函数如何将数据帧的字符串字符转换为大写。
![Upp 1](https://i-blog.csdnimg.cn/blog_migrate/f2c184760262fc12db5de82ef9c0325b.png)
使用R中的casefold()函数将字符串转换为大写和小写 (Convert a string to upper and lower case using casefold() function in R)
Till now, we have come across tolower() and toupper() functions to convert the case of the strings to lower and upper cases respectively.
到现在为止,我们来了 跨tolower()和toupper()函数将字符串的大小写分别转换为小写和大写。
R offers another function named casefold(), which converts the string characters to lower and upper case.
R提供了另一个名为casefold()的函数,该函数将字符串字符转换为小写和大写形式。
The syntax:
语法:
casefold(x,upper=F)
Where,
哪里,
- x = string character or a character data frame. x =字符串字符或字符数据帧。
- upper = case of the string will be lower if mentioned False and it will be upper if mentioned True. upper =如果为False,则字符串的大小写将为小写;如果为True,则字符串的大小写将为大写。
Let’s see how the casefold() function converts the case of the strings.
让我们看看casefold()函数如何转换字符串的大小写。
casefold("i love r programming",upper = T)
Output = “I LOVE R PROGRAMMING”
输出=“我爱编程”
casefold("I LOVE R PROGRAMMING",upper=F)
Output = “i love r programming”
输出=“我爱编程”
Like this the casefold() function will convert the case of the string characters. Now, let’s see how casefold() function will convert the case of the data frame.
这样,casefold()函数将转换字符串字符的大小写。 现在,让我们看看casefold()函数将如何转换数据帧的大小写。
The below image shows the state.name data frame.
下图显示了state.name数据框。
![Casefold](https://i-blog.csdnimg.cn/blog_migrate/fa6463e9de80b40808cbf666e04be5a6.png)
Let’s make use of casefold() function to convert the strings present in the data frame to upper case.
让我们利用casefold()函数将数据框中存在的字符串转换为大写。
casefold(state.name,upper = T)
![Casefold 1](https://i-blog.csdnimg.cn/blog_migrate/214655fd6d3536ccb5885cd9e34a1f35.png)
In this way, you can convert the case of the strings in R using tolower(), toupper(), and casefold() function.
这样,您可以使用tolower(),toupper()和casefold()函数在R中转换字符串的大小写。
结语 (Wrapping up)
R offers some functions to convert the case of the string characters present in a vector or a data frame.
R提供了一些功能来转换矢量或数据帧中存在的字符串字符的大小写。
This tutorial focussed on the case conversion using some specific functions in R.
本教程重点介绍使用R中的某些特定功能进行大小写转换。
That’s all for case conversion in R. Stay tuned for more updates on R programming tutorials. Happy conversion!!!
这就是R中的大小写转换。敬请期待有关R编程教程的更多更新。 转换愉快!!!
翻译自: https://www.journaldev.com/40542/convert-case-of-a-string-in-r
mysql中转换成字符串