iOS笔记 - 字符串处理

Unicode

计算机没法直接处理文本,他只和数字打交道。为了计算机里显示文字,我们指定了一个从数字到字符的映射,这个映射就叫做编码。
最有名的字符串编码是 ASCII (/ˈæski/ ASS-kee)

字符串排序

  • NSNumberSearch :对字符串数字排序,“Section10” < “Section100” < “Section1000”
  • NSDiacriticInsensitiveSearch :“A” 等同于 “Å” 等同于 “Ä.”
  • NSWidthInsensitiveSearch :一些东亚文字(平假名和片假名)有全宽与半宽两种形式。

一般我们使用 -localizedStandardCompare 它排序的方式和 Finder 一样。它对应的选项是 NSCaseInsensitiveSearchNSNumericSearchNSWidthInsensitiveSearch 以及 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;
}

你可能感兴趣的:(iOS笔记 - 字符串处理)