java字串擷取相關操作 原創

2021-08-25 08:00:08 字數 1167 閱讀 3517

擷取等號 」=「 之後的連同=一起的字元出來:

string aa = 「622439490117870217=491212050900000000「;

aa.substring(aa.indexof("="));

擷取後幾位:

aa = "123456789"

aa.substring(aa.length-6)//後六位

**********===以下是**的內容:*************************==

str=str.substring(int beginindex);擷取掉str從首字母起長度為beginindex的字串,將剩餘字串賦值給str;

str=str.substring(int beginindex,int endindex);擷取str中從beginindex開始至endindex結束時的字串,並將其賦值給str;

以下是一段演示程式:

public class stringdemo

else

system.out.println("string \""+todelete+"\" not found");

}system.out.println(str);

} }*************************===

substring

public string substring(int beginindex,

int endindex)

返回乙個新字串,它是此字串的乙個子字串。該子字串從指定的 beginindex 處開始,一直到索引 endindex - 1 處的字元。因此,該子字串的長度為 endindex-beginindex。

示例:"hamburger".substring(4, 8) returns "urge"

"smiles".substring(1, 5) returns "mile"

引數:

beginindex - 開始處的索引(包括)。

endindex - 結束處的索引(不包括)。

返回:

指定的子字串。

丟擲:

indexoutofbound***ception - 如果 beginindex 為負,或 endindex 大於此 string 物件的長度,或 beginindex 大於 endindex。

java字串擷取相關方法

1.split 正規表示式來進行擷取。將正則傳入split 返回的是乙個字串陣列型別。不過通過這種方式擷取會有很大的效能損耗,因為分析正則非常耗時。1 2 3 4 5 string str abc,12,3yy98,0 string strs str.split for int i 0,len st...

java字串擷取

一 split 正規表示式string str abc,12,3yy98,0 string strs str.split for int i 0,len strs.length iout.println strs i tostring 執行結果 abc 123yy98 0二 通過substring ...

java 字串擷取

一 獲取字串索引 string ss 12323,sdfdf int i ss.indexof 1 int indexof string str 返回第一次出現的指定子字串在此字串中的索引。2 int indexof string str,int startindex 從指定的索引處開始,返回第一次...