/*
1 controlcharacterset //控制符
2 whitespacecharacterset //空格符號
3 whitespaceandnewlinecharacterset //空格換行
4 decimaldigitcharacterset //小數
5 lettercharacterset //文字
6 lowercaselettercharacterset //小寫字母
7 uppercaselettercharacterset //大寫字母
8 nonbasecharacterset //非基礎 (漢字英文就屬於非基礎)
9 alphanumericcharacterset //字母數字
10 decomposablecharacterset //可分解
11 illegalcharacterset //非法
12 punctuationcharacterset //標點
13 capitalizedlettercharacterset //大寫
14 symbolcharacterset //符號
15 newlinecharacterset //換行符
*/
//字母nsmutablecharacterset *zimuchar = [nsmutablecharacterset lowercaselettercharacterset];
//十進位制數字
nsmutablecharacterset *suzhichar = [nsmutablecharacterset decimaldigitcharacterset];
nsstring *mainstr = @"asdfg123qwerty123zxcvb123";
//把所有的字母去掉,用-拼接
nsstring *newstr1 = [[mainstr componentsseparatedbycharactersinset:zimuchar] componentsjoinedbystring:@"-"];
nslog(@"%@",newstr1); //-----123------123-----123
//把所有的數字去掉,用-拼接
nsstring *newstr3 = [[mainstr componentsseparatedbycharactersinset:suzhichar] componentsjoinedbystring:@"-"];
nslog(@"%@",newstr3); // asdfg---qwerty---zxcvb---
//去掉所有的數字和字母
[zimuchar formunionwithcharacterset:suzhichar];
nsstring *newstrnew = [[mainstr componentsseparatedbycharactersinset:zimuchar] componentsjoinedbystring:@"-"];
nslog(@"%@",newstrnew); //-------------------------
//作用相反
//把除了字母意外的,全部用-拼接
[zimuchar invert];
nsstring *newstr2 = [[mainstr componentsseparatedbycharactersinset:zimuchar] componentsjoinedbystring:@"-"];
nslog(@"%@",newstr2); //asdfg---qwerty---zxcvb---
//作用相反。把除了數字意外的,全部用-拼接
[suzhichar invert];
nsstring *newstr4 = [[mainstr componentsseparatedbycharactersinset:suzhichar] componentsjoinedbystring:@"-"];
nslog(@"%@",newstr4); //-----123------123-----123
//字母留下 + 字母去掉,留下數字 = 數字留下
//最終還是留下所有的數字
[zimuchar formunionwithcharacterset:suzhichar];
nsstring *newstrnewinvert = [[mainstr componentsseparatedbycharactersinset:zimuchar] componentsjoinedbystring:@"-"];
nslog(@"%@",newstrnewinvert); //-----123------123-----123
nsstring *strmsg = @" 我愛 北京天安門";
//去掉前後兩端的空格
nsstring *strresult = [strmsg stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]];
nslog(@"%@",strmsg); // 我愛 北京天安門
nslog(@"%@",strresult); //我愛 北京天安門
//去掉首尾制定的字符集 (必須是在最前、嘴壺)
nsstring *strmsg2 = @"我愛 北京天安門";
nscharacterset *cs = [nscharacterset charactersetwithcharactersinstring:@"天安門"];
nsstring *strresult2 = [strmsg2 stringbytrimmingcharactersinset:cs];
nslog(@"%@",strresult2); //我愛 北京 (後面無空格)
nscharacterset *cs2 = [nscharacterset charactersetwithcharactersinstring:@"我愛"];
nsstring *strresult3 = [strmsg2 stringbytrimmingcharactersinset:cs2];
nslog(@"%@",strresult3); // 北京天安門 (前面有空格)
nsmutablestring *strmsg3 = [[nsmutablestring alloc] initwithstring:@"我愛北京天安門"];
nscharacterset *cs3 = [nscharacterset charactersetwithcharactersinstring:@"北京"];
nsstring *strresult4 = [self clearnillegitcharacters:strmsg3 andcharacterset:cs3];
nslog(@"%@",strresult4);
- (nsstring *)clearnillegitcharacters:(nsmutablestring *)originstring andcharacterset:(nscharacterset *)cs
} while (range2.location!=nsnotfound);
strresult=[[nsstring alloc] initwithstring:originstring];
return strresult;
}
NSCharacterSet 簡單用法
nscharacterset其實是許多字元或者數字或者符號的組合,在網路處理的時候會用到 nsmutablecharacterset base nsmutablecharacterset lowercaselettercharacterset 字母 nscharacterset decimaldig...
對建立游標對理解
步驟 1 首先經過底層的 編寫已經建立起了了python和資料庫之間的溝通橋梁並封裝成了模組,通過pymysql下的conntent 方法與之建立起了連線,例項物件。pymysql.connect 方法返回的是connections模組下的connection 例項,connect 方法傳參就是在給...
對勾函式 對勾函式
對勾函式是一種類似於反比例函式的一般函式。所謂的對勾函式,是形如 f x ax b x 的函式,是 一種教材上沒有但考試老喜歡考的函式,所以更加要注意和學習。一般的函式影象形似兩個中心對稱的 對勾,故名。當x 0 時,f x ax b x 有最小值 這裡為了研究方便,規定a 0 b 0 也就是當 x...