如何獲得字串最後字元,如何獲得字串最後一個字元

2022-10-20 09:36:42 字數 513 閱讀 2734

1樓:

用string類的substring(int from,int to)方法去截字串位置為from到to-1位置的字元

substring(int index)方法去截字串位置index-1及以後的所有字串,注意字串的字元位置是從0開始的,substring(int from ,int to)方法是前閉後開的,即[from,to),可以理解為[from,to-1]

例:string name="helloworld";

system.out.println(name.substring(name.length()-1,name.length()));//輸出d

system.out.println(name.substring(name.length()-1));//輸出d

2樓:匿名使用者

string aaa="12345.67890"

aaa.substring(0,aaa.lastindexof(.));

有字元陣列,每元素都是字串,如何獲得每字串的長度

取得的字元陣列長度與使用的獲取長度的方法有關,在c c 中常用的獲取字串長度或者字串陣列長度的函式有sizeof strlen sizeof 求出的是陣列的總長度,而不是陣列中存放的有意義的資料的個數。比如定義一個int型的陣列 int a 10 只初始化了五個元素,但是 sizeof a size...

js中如何判斷字串中是否包含指定字串

正則bai 匹配 du var str this is my test var test new regexp test g 建立正 zhi則dao表達版式對權 象var result s.match test alert result js判斷字串變數是否含有某個字串的方法 方法一 var str...

如何判斷字串是否相等,判斷字串是否有值,判斷多個字串是否相等

string str1 abc string str2 bcd if str1.equals str2 用的是專equals 方法屬 先要包含string.h 標頭檔案,再用以下 比較str1與str2二個字串是否相等 if strcmp str1,str2 0 在pl sql怎麼判斷兩個字串是否相...