字串處理

2021-07-22 07:49:21 字數 1919 閱讀 8512

[nscharacterset

alphanumericcharacterset

];          

//所有數字和字母(大小寫)

[nscharactersetdecimaldigitcharacterset

];          

//0-9的數字

[nscharactersetlettercharacterset

];                

//所有字母

[nscharactersetlowercaselettercharacterset

];       

//小寫字母

[nscharactersetuppercaselettercharacterset

];       

//大寫字母

[nscharactersetpunctuationcharacterset

];           

//標點符號

[nscharactersetwhitespaceandnewlinecharacterset

];  

//空格和換行符

[nscharactersetwhitespacecharacterset

];            

//空格

nsstring *examplestr = @" my name    is johnny!";

examplestr = [examplestr stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]];

nsarray *examplearr = [examplestr componentsseparatedbycharactersinset:[nscharacterset whitespacecharacterset]];

nspredicate *predicate = [nspredicate predicatewithformat:@"self <> ''"];

examplearr = [examplearr filteredarrayusingpredicate:predicate];

examplestr = [examplearr componentsjoinedbystring:@" "];

nsmutablecharacterset

*set

1= [nsmutablecharacterset

charactersetwithcharactersinstring

:@"hell"

];  

nsmutablecharacterset

*set

2= [nsmutablecharacterset

charactersetwithcharactersinstring

:@"ello"

]; //去掉某些字元

[set2

removecharactersinstring

:@"e"

]; //--->l, o

//加上某些字元

[set2

addcharactersinstring

:@"e"

];    

//--->e, l, o

//set相加

[set2

formunionwithcharacterset

:set

1]; 

//--->h,e,l,o

//set交集

[set2

formintersectionwithcharacterset

:set

1]; 

//--->e,l 

//set取反

[set2

invert

];  

字串處理 字串反轉

請原諒博主今天很閒,於是乎博主又開始更新微博了。這次要更新的問題是 編寫乙個函式,反轉乙個單詞的順序。例如 do or do not,there is no try.就要反轉成 try.no is there not,do or do 大家要認真看看這道題,這道題和大家想象的貌似有點不同。首先字串反...

字串處理

uncode與ansi字串轉換 我們使用windows函式multibytetowidechar將多位元組字串轉換成寬字元字串。函式如下 int multibytetowidechar uintcodepage dworddwflags lpcstrlpmultibytestr intcbmulti...

字串處理

byte array new byte 2 array system.text.encoding.default.getbytes 啊 int i1 short array 0 0 int i2 short array 1 0 unicode解碼方式下的漢字碼 array system.text.e...