字串操作常用的函式總結

2021-08-16 02:37:33 字數 746 閱讀 9823

//一直都想把字串操作常用的函式總結一些,不全但重在積累;

字串的比較:

語法:

int compare( const basic_string &str );

int compare( const char *str );

int compare( size_type index, size_type length, const basic_string &str );

int compare( size_type index, size_type length, const basic_string &str, size_type index2,

size_type length2 );

int compare( size_type index, size_type length, const char *str, size_type length2 );

compare()函式以多種方式比較本字串和str,返回:

返回值情況

小於零this < str

零this == str

大於零this > str

不同的函式:

示例**:

#include #include using namespace std;

int main( )

; cout

}

python 字串操作常用函式總結

s ilovepython s 0 i s 1 n s ilovepython s 1 5 s 開始下標,包含 結束下標,不包含 love s 5 左下標省略表示 從0開始,等同於 s 0 5 s 1 左邊從0開始,去掉最後乙個字元,其作用是去掉字串尾字元。a hello word a.replac...

字串操作常用函式

puts printf s p gets 記憶體是否合法 scanf s p strlenmemset memset params初始化物件,初始化成什麼字元,多大 strcpy strcpy 目標,複製物件 strncpy 拷貝的最大長度 strncpy 目標,複製物件,長度 strcat str...

PHP字串常用函式總結

函式名 功能描述 ltrim 刪除字串開頭的空白字元 或其他字元 rtrim 刪除字串末端的空白字元 或者其他字元 trim 去除字串首尾處的空白字元 或者其他字元 str pad 使用另乙個字串填充字串為指定長度 strtolower 將字串轉化為小寫 strtoupper 將字串轉化為大寫 uc...