字符串的大小写转化

javascript中string对象总共有四个涉及到大小写的函数:

1、toLowerCase()  把字符串转换为小写。

2、toUpperCase()  把字符串转换为大写。

3、toLocaleLowerCase()  把字符串转换为小写。

4、toLocaleUpperCase()  把字符串转换为大写。

那上面两个函数与下面的两个函数有什么区别呢?3/4都是按照本地方法把字符串转化为相应的大小写,只有几种语言(例如土耳其语)尤其特定的大小写映射,其余的返回值和1/2一模一样。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现C字符串大小写换,可以使用以下方法之一: 方法一:使用string类 可以自己手写两个转化为大写和小写的方法,如下所示: ```cpp #include <iostream> #include <algorithm> #include <cstring> using namespace std; void mytolower(string& s){ int len = s.size(); for(int i = 0; i < len; i++){ if(s[i >= 'A' && s[i <= 'Z'){ s[i += 32; // 32换为小写 } } } void mytoupper(string& s){ int len = s.size(); for(int i = 0; i < len; i++){ if(s[i >= 'a' && s[i <= 'z'){ s[i -= 32; // 32换为大写 } } } int main() { cout << "请输入一个含大写的字符串:"; string str; cin >> str; // 小写 mytolower(str); cout << "转化为小写后为:" << str << endl; // 大写 mytoupper(str); cout << "转化为大写后为:" << str << endl; return 0; } ``` 方法二:使用char数组 如果使用char数组,可以使用`s[i] = 32`或者`s[i] = s[i] - 'A' + 'a'`的形式,实现两个转化为大写和小写的方法,如下所示: ```cpp #include <iostream> #include <algorithm> #include <cstring> using namespace std; void mytolower(char *s){ int len = strlen(s); for(int i = 0; i < len; i++){ if(s[i >= 'A' && s[i <= 'Z'){ s[i += 32; // 32换为小写 } } } void mytoupper(char *s){ int len = strlen(s); for(int i = 0; i < len; i++){ if(s[i >= 'a' && s[i <= 'z'){ s[i -= 32; // 32换为大写 } } } int main() { cout << "请输入一个含大写的字符串:"; char s >= 'A' && s[i <= 'Z'){ s[i = tolower(s[i]); } } } void mytoupper(char *s){ int len = strlen(s); for(int i = 0; i < len; i++){ if(s[i >= 'a' && s[i <= 'z'){ s[i = toupper(s[i]); } } } int main() { cout << "请输入一个含大写的字符串:"; char s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值