字串String的 簡單處理

2021-08-03 10:02:03 字數 773 閱讀 4263

(1)charat(int index)獲取指定位置的字元

public class teststring (2)tochararray() 獲取對應的字串陣列 converts this string to a new character array.

public class teststring (3)擷取子字串 substring(int beginindex, int endindex) substring(int beginindex)

public class teststring }

(4)分隔 split(string regex) splits this string around matches of the given regular expression.

split(string regex, int limit)

public class teststring

}} (5) tolowercase 全部變成小寫

touppercase 全部變成大寫

public class teststring }

(6)indexof 判斷字元或者子字串出現的位置,contains 是否包含子字串

public class teststring

} (7)replaceall 替換所有的 replacefirst 只替換第乙個

public class teststring stringbuffer是可變長的字串

public class teststring

C 字串處理string

之所以拋棄char 的字串而選用c 標準程式庫中的string類,是因 為他和前者比較起來,不必擔心記憶體是否足夠 字串長度等等,而且作為乙個類出現,他整合的操作函式足以完成我們大多數情況下 甚至是100 的需要。我們可以用 進行賦值操作,進行比較,做串聯。我們盡可以把它看成是c 的基本資料型別。首...

字串處理 string型別

string型別變數的賦值與連線 s是字串變數名 一 string s 字串 定義並初始化 二 string s 個數,字元 定義並初始化為若干相同字母 三 string s 字串 定義並初始化賦值 四 s 字元 字串變數名 連線字串 string型別的運算 成員函式指某個型別的特有函式,其呼叫方式...

簡單的字串處理

題目背景 某蒟蒻迷上了 小書童 有一天登陸時忘記密碼了 他沒繫結郵箱or手機 於是便把問題拋給了神犇你。題目描述 蒟蒻雖然忘記密碼,但他還記得密碼是由一串字母組成。且密碼是由一串字母每個向後移動n為形成。z的下乙個字母是a,如此迴圈。他現在找到了移動前的那串字母及n,請你求出密碼。均為小寫 輸入輸出...