1.在一些字串陣列中,常會有重複的記錄,比如手機號碼,我們可以通過hashtable來對其進行過濾
public string checkarray(string str)...
return str_new;
}示例:
string mobile=;
mobile=checkarray(mobile);
for(int i=0;ihash=new hashtable();
hashtablehash_new=new hashtable();
for(int i=0;ifor(int i=0;istring c=new string[hash_new.size()];
int i=0;
enumeration enumeration=hash_new.keys();
while(enumeration.hasmoreelements())
return c;
}示例:
string mobile1=;
string mobile2=;
string mobile3=comparearray(mobile1,mobile2);
for(int i=0;i3.將乙個字串陣列中某乙個特定的字串過濾掉
/** *//**檢驗乙個字串陣列,若包含某一特定的字串,則將該字串從陣列中刪
除,返回剩餘的字串陣列
* @param str_array 字串陣列
* @param str_remove 待刪除的字串
* @return 過濾後的字串
*/public string removestrfromarray(string str_array,string
str_remove)...
//生成乙個新的陣列
string str_new=new string[hash.size()];
int i=0;
enumeration enumeration=hash.keys();
while(enumeration.hasmoreelements())...
return str_new;
}
對串 旋轉字串
題目 旋轉字串 對串 描述s 0.n 1 是乙個長度為n的字串,定義旋轉函式left s s 1 n 1 s 0 比如s abcd left s bcda 乙個串是對串當且僅當這個串長度為偶數,前半段和後半段一樣。比如 abcabc 是對串,aabbcc 則不是。現在給你字串,判斷他是否可以由乙個對...
對字串切片
字串 和 unicode字串 u 也可以看成是一種list,每個元素就是乙個字元。因此,字串也可以用切片操作,只是操作結果仍是字串 abcdefg 3 abc abcdefg 3 efg abcdefg 2 aceg 在很多程式語言中,針對字串提供了很多各種擷取函式,其實目的就是對字串切片。pyth...
對字串排序
def main 字串 s helloworld 轉換成陣列 l list s 對陣列排序,注意,該方法沒有返回值 l.sort 轉換成陣列 s join l print s 結果如下 hwdellloor if name main main 然後sort再join。def main s hello...