1、substring()用法:這個函式返回第乙個引數中從第二個引數指定的位置開始、第三個引數指定的長度的子字串。
該字串中的每個字元都被認為具有數字位置:第乙個字元的位置是 1,第二個字元的位置是 2,依此類推。
如果未指定第三個引數,將返回從第二個引數指定的位置開始直到字串結尾的子字串。
如果引數不是字串型別,將先使用 string() 函式轉換為字串,然後計算該轉換的結果。
如:以下函式呼叫返回「234」: substring("12345",2,3)
public class stringtest
public static int getsubcount(string str,string key)
return count;
}public static void sop(string str)
}2、int indexof(string str):返回字元中indexof(string)中字串string在父串中首次出現的位置,從0開始!
沒有返回-1;方便判斷和擷取字串!
3、int length();獲取長度。
4、int charat(int index):根據位置獲取某個位置上的字元。
5、int indexof(string str,int fromindex):返回指定字串str第一次出現的索引,從指定的索引開始搜尋。
public class stringtest
public static int getsubcount(string str,string key)
return count;
}public static int getsubcount_2(string str,string key)
return count;
}public static void sop(string str)
}6、int indexof(int ch,int fromindex):返回指定字元ch第一次出現的索引,從指定的索引開始搜尋。
string類一些常用函式用法
insert string的成員函式insert有以下多種過載 string insert int p0,const char s 在p0位置插入字串s string insert int p0,const char s,int n 在p0位置插入字串s的前n個字元 string insert in...
PHP中String一些用法
1.利用索引選字 js中字串可以利用str.charat 索引 選取字串的某個字。php中則是使用 str 索引 或者 str.僅對非中文本元 2.型別轉換 判斷裡,字元只有是 空字串的時候為false,空格是true,false 也是true.反過來true轉換成字串strval false 是空...
C 中的string的一些用法
1 string與字元陣列轉換 const char c string s 1234 c s.c str 2 char轉化為string char c a string s 1 c 3 擷取子串 std string str helloworld std string str2 str.substr...