1

coder  •  14小时前


include "bits/stdc++.h"

using namespace std;

int main() {

string s,s1;

// s = "abcdefg"; // s1 = "123"; // 1、求长度 // size() 、 length() // int a = s.size(); // int b = s.length(); // 2、插入字符串 // 变量名.insert(pos(int 类型的位置(下标)),string (插入的东西)) // s.insert(3,s1); // 3、删除方法 // erase // 变量名.erase(pos,len);从pos开始删除len长度的字符串 // 如果不写长度的话,是吧pos后全部删除 // s.erase(1); //// cout << s.length(); // 4、提取子字符串 // string s1 = 变量名.substr(pos,len)从pos开始提取len长度的字符串 // string s2 = s.substr(2);

// 5、查找字符串 // find() // int t = s.find("str",pos) 从s的pos下标开始往后查找有没有str这个字符串 // 如果有会返回第一次出现的下标,如果没有返回-1. // string s2 = "z"; // int t = s.find(s2,0); // cout <<t; // 6、比较函数 compare // int t = s.compare(s1); // 如果s和s1相等 t = 0; // 如果s>s1 t= 1 // 如果s<s1 t = -1

// s="123"; // s1="1234"; // int t = s1.compare(s); // cout <<t;

// 7、转大写/小写 // 大写:toupper // 小写:tolower // s = "AbCdEfGh"; // for (int i = 0; i < s.size(); ++i) { // s[i] = tolower(s[i]); // }

// 8、判断该字符是不是数字字符

// isdigit() // s = "A1bCd3f3Gh"; // for (int i = 0; i < s.size(); ++i) { // cout << isdigit(s[i]); // } // cout << s; // return 0; }


评论:

请先登录,才能进行评论