【C++中的string字符串常用函数】tolower(), toupper(), isalnum(), isdigit(), islower(), isupper(), isalpha()

  • tolower()/toupper():将字符串string转换大小写
  • isalnum():判断字符串是否为字母+十进制数字
  • isdigit():判断字符串是否为十进制数字
  • islower(): 判断字符串是否为小写
  • isupper(): 判断字符串是否为大写
  • isalpha(): 判断字符串是否为字母
  • substr(pos, len):提取字符串从pos开始的长度为len的子串
#include <iostream>
#include <string>

int main() {
    
    
    std::string str = "Hello, World!";
    
    // 提取从索引位置5开始的子字符串,并将其存储到newStr中
    std::string newStr = str.substr(5);
    std::cout << "New string: " << newStr << std::endl;
    
    // 提取从索引位置6开始,长度为6的子字符串,并将其存储到newStr2中
    std::string newStr2 = str.substr(6, 6);
    std::cout << "New string 2: " << newStr2 << std::endl;
    
    return 0;
}
New string: , World!
New string 2: World!

猜你喜欢

转载自blog.csdn.net/m0_48086806/article/details/132228505