處理字串常用的函式

2021-10-12 04:56:31 字數 627 閱讀 9562

stoi()

stol()

stoul()

stoll()

stoull()

stof()

stod()

stold()

to_string()

這些加起來有9個函式,但實際上只用2個就夠了。

一:stoi()其作用是將string類的字串轉化為 int 型別的數字,比如乙個 string s=;那麼就可以利用stoi將它轉化為乙個int型別的數。

記住了這個後剩下的7個就自然知道什麼意思了!

規律:sto+型別a的縮寫()=將string類轉為 型別a的數字。

stol()就是將string類轉化為long 型別。

stod()就是將string類轉化為double 型別。

stoul()就是將string類轉化為unsigned long 型別。

以此類推。

二:to_string()其作用和sto類相反,為將數字轉化為string型別。

比如:int a=123;string s=to_string(a);

那麼s=;

這些函式庫在處理一些字串問題的時候十分有效,但要注意要使用它們,本地的編譯器一定要是c++11以上,不然不具有此功能!

C String字串處理常用函式

下面是幾個string類用於提取字串的常用方法 1.str.find str2,pos 從str的pos位開始查詢匹配str2,並返回其在str中第一次出現的位置,pos沒有賦值的話預設為0 string str1 test string str2 t unsigned int index if s...

Python 字串處理常用函式

python處理字串有很多常用函式 1.使用成員操作符in str hello,world n sstr n result sstr in str print result true2.使用字串的find index 火count 方法 str hello,world n sstr n result...

常用SQL字串處理函式

一 字元轉換函式 3 lower 和upper lower 將字串全部轉為小寫 upper 將字串全部轉為大寫。4 str 把數值型資料轉換為字元型資料。str length length 指定返回的字串的長度,decimal 指定返回的小數字數。如果沒有指定長度,預設的length 值為10,de...