StringTokenizer 字串分隔類

2021-06-28 10:42:51 字數 1471 閱讀 9730

string teststring = "1,2,3";

stringtokenizer st = new stringtokenizer(teststring.trim(), ",");

while(st.hasmoretokens()) for the parameter string using

* the specified delimiters. the flag is set to

* . if is , this constructor 

* doesn't throw an , but later calls to some methods might 

* throw a .

* @param string

*                   the string to be tokenized

* @param delimiters 

*                 the delimiters to use

//用特定的分隔符分割輸入的字串引數,構造乙個字串分割類。 返回分隔符標記為假。如果分隔符引數是空,構造器不會丟擲異常,但是隨後呼叫其他方法時可能會丟擲     //空指標異常。

public stringtokenizer(string string, string delimiters)

public stringtokenizer(string string, string delimiters, boolean returndelimiters) if unprocessed tokens remain.

** @return if unprocessed tokens remain.

*/public boolean hasmoretokens()

int length = string.length();

if (position < length)

return false;

}/**

* returns the next token in the string as a .

** @return next token in the string as a .

* @throws nosuchelementexception

*                if no tokens remain.

*/public string nexttoken()

int i = position;

int length = string.length();

if (i < length)

while (i < length && delimiters.indexof(string.charat(i), 0) >= 0)

i++;

position = i;

if (i < length)

}throw new nosuchelementexception();

}

字串分隔

題目 連續輸入字串,請按長度為8拆分每個字串後輸出到新的字串陣列 長度不是8整數倍的字串請在後面補數字0,空字串不處理。輸入 abc 123456789輸出 abc00000 12345678 90000000 include include using namespace std char str...

分隔字串

注 此sql原作者 袁老大 create or replace package split pck is type char table is table of varchar2 4000 function split string pi str in varchar2,pi separator i...

字串分隔

連續輸入字串,請按長度為8拆分每個字串後輸出到新的字串陣列 長度不是8整數倍的字串請在後面補數字0,空字串不處理。連續輸入字串 輸入2次,每個字串長度小於100 輸出到長度為8的新字串陣列。abc 123456789abc00000 12345678 90000000華為機試題。我的思路是先假設輸入...