Unicode
計算機沒法直接處理文本,他只和數(shù)字打交道。為了計算機里顯示文字,我們指定了一個從數(shù)字到字符的映射,這個映射就叫做編碼。
最有名的字符串編碼是 ASCII (/??ski/ ASS-kee)
字符串排序
- NSNumberSearch :對字符串?dāng)?shù)字排序,“Section10” < “Section100” < “Section1000”
- NSDiacriticInsensitiveSearch :“A” 等同于 “?” 等同于 “?.”
- NSWidthInsensitiveSearch :一些東亞文字(平假名和片假名)有全寬與半寬兩種形式。
一般我們使用 -localizedStandardCompare 它排序的方式和 Finder 一樣。它對應(yīng)的選項是 NSCaseInsensitiveSearch、NSNumericSearch、NSWidthInsensitiveSearch 以及 NSForcedOrderingSearch。
技巧:多行文字的時候這樣寫可讀性更高:
NSString *limerick = @"A lively young damsel named Menzies\n"
@"Inquired: ?Do you know what this thenzies??\n"
@"Her aunt, with a gasp,\n"
@"Replied: "It's a wasp,\n"
@"And you're holding the end where the stenzies.\n”;
對象描述
自定義對象中,重寫 description 方法對象可以直接打印出來
- (NSString *)description
{
return self.name;
}