0%

一些有趣的事

\U0000202E (2016.6.3)

今天在项目中遇到一个很有意思的事情,测试在编辑用户昵称的时候,不知道从哪里copy了一个特殊字符\U0000202E,然后我们在label上面显示的时候就出问题了,本来应该是wind参加了活动,结果变成了wind动活了加参,当时我就懵逼了,后面断点调试,发现字符串为wind\U0000202E参加了活动。后面我在Google上搜索\U0000202E,只搜到了两条结果

http://permalink.gmane.org/gmane.comp.lib.regexp.tre/39 https://github.com/nbjahan/launchbar-unisym/blob/master/src/2000-206f_general_punctuation.go

然后我把第一条链接里面的所提及用demo运行效果出来了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    static NSArray *charArray = nil;
    if (!charArray) {
        charArray = @[@"\U0000200E", @"\U0000200F", @"\U0000200B", @"\U0000202A", @"\U0000202E", @"\U00002060", @"\U0000206A", @"\U0000206F"];
    }
    if (indexPath.row < [charArray count]) {
        NSString *text = [NSString stringWithFormat:@"%@+%@-%@", @(indexPath.row + 1), charArray[indexPath.row], @"一颗赛艇"];
        NSString *length = @(text.length).stringValue;
        NSInteger index = [text rangeOfString:charArray[indexPath.row]].location;
        cell.textLabel.text = text;
        cell.detailTextLabel.text = [NSString stringWithFormat:@"length:%@ index:%@", length, @(index)];
    }
    return cell;
}

代码运行效果图

下面是第二个链接的东西,是一个数组,关于unicode码以及它的相关含义。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
func init() {

chars["02000"] = [][2]string{

// {"En Quad", "\U00002000"},

// {"Em Quad", "\U00002001"},

// {"En Space", "\U00002002"},

// {"Em Space", "\U00002003"},

// {"Three-Per-Em Space", "\U00002004"},

// {"Four-Per-Em Space", "\U00002005"},

// {"Six-Per-Em Space", "\U00002006"},

// {"Figure Space", "\U00002007"},

// {"Punctuation Space", "\U00002008"},

// {"Thin Space", "\U00002009"},

// {"Hair Space", "\U0000200a"},

// {"Zero Width Space", "\U0000200b"},

// {"Zero Width Non-Joiner", "\U0000200c"},

// {"Zero Width Joiner", "\U0000200d"},

// {"Left-To-Right Mark", "\U0000200e"},

// {"Right-To-Left Mark", "\U0000200f"},

{"Hyphen", "\U00002010"},

{"Non-Breaking Hyphen", "\U00002011"},

{"Figure Dash", "\U00002012"},

{"En Dash", "\U00002013"},

{"Em Dash", "\U00002014"},

{"Horizontal Bar", "\U00002015"},

{"Double Vertical Line", "\U00002016"},

{"Double Low Line", "\U00002017"},

{"Left Single Quotation Mark", "\U00002018"},

{"Right Single Quotation Mark", "\U00002019"},

{"Single Low-9 Quotation Mark", "\U0000201a"},

{"Single High-Reversed-9 Quotation Mark", "\U0000201b"},

{"Left Double Quotation Mark", "\U0000201c"},

{"Right Double Quotation Mark", "\U0000201d"},

{"Double Low-9 Quotation Mark", "\U0000201e"},

{"Double High-Reversed-9 Quotation Mark", "\U0000201f"},

{"Dagger", "\U00002020"},

{"Double Dagger", "\U00002021"},

{"Bullet", "\U00002022"},

{"Triangular Bullet", "\U00002023"},

{"One Dot Leader", "\U00002024"},

{"Two Dot Leader", "\U00002025"},

{"Horizontal Ellipsis", "\U00002026"},

{"Hyphenation Point", "\U00002027"},

// {"Line Separator", "\U00002028"},

// {"Paragraph Separator", "\U00002029"},

// {"Left-To-Right Embedding", "\U0000202a"},

// {"Right-To-Left Embedding", "\U0000202b"},

// {"Pop Directional Formatting", "\U0000202c"},

// {"Left-To-Right Override", "\U0000202d"},

// {"Right-To-Left Override", "\U0000202e"},

// {"Narrow No-Break Space", "\U0000202f"},

{"Per Mille Sign", "\U00002030"},

{"Per Ten Thousand Sign", "\U00002031"},

{"Prime", "\U00002032"},

{"Double Prime", "\U00002033"},

{"Triple Prime", "\U00002034"},

{"Reversed Prime", "\U00002035"},

{"Reversed Double Prime", "\U00002036"},

{"Reversed Triple Prime", "\U00002037"},

{"Caret", "\U00002038"},

{"Single Left-Pointing Angle Quotation Mark", "\U00002039"},

{"Single Right-Pointing Angle Quotation Mark", "\U0000203a"},

{"Reference Mark", "\U0000203b"},

{"Double Exclamation Mark", "\U0000203c"},

{"Interrobang", "\U0000203d"},

{"Overline", "\U0000203e"},

{"Undertie", "\U0000203f"},

{"Character Tie", "\U00002040"},

{"Caret Insertion Point", "\U00002041"},

{"Asterism", "\U00002042"},

{"Hyphen Bullet", "\U00002043"},

{"Fraction Slash", "\U00002044"},

{"Left Square Bracket With Quill", "\U00002045"},

{"Right Square Bracket With Quill", "\U00002046"},

{"Double Question Mark", "\U00002047"},

{"Question Exclamation Mark", "\U00002048"},

{"Exclamation Question Mark", "\U00002049"},

{"Tironian Sign Et", "\U0000204a"},

{"Reversed Pilcrow Sign", "\U0000204b"},

{"Black Leftwards Bullet", "\U0000204c"},

{"Black Rightwards Bullet", "\U0000204d"},

{"Low Asterisk", "\U0000204e"},

{"Reversed Semicolon", "\U0000204f"},

{"Close Up", "\U00002050"},

{"Two Asterisks Aligned Vertically", "\U00002051"},

{"Commercial Minus Sign", "\U00002052"},

{"Swung Dash", "\U00002053"},

{"Inverted Undertie", "\U00002054"},

{"Flower Punctuation Mark", "\U00002055"},

{"Three Dot Punctuation", "\U00002056"},

{"Quadruple Prime", "\U00002057"},

{"Four Dot Punctuation", "\U00002058"},

{"Five Dot Punctuation", "\U00002059"},

{"Two Dot Punctuation", "\U0000205a"},

{"Four Dot Mark", "\U0000205b"},

{"Dotted Cross", "\U0000205c"},

{"Tricolon", "\U0000205d"},

{"Vertical Four Dots", "\U0000205e"},

// {"Medium Mathematical Space", "\U0000205f"},

// {"Word Joiner", "\U00002060"},

{"Function Application", "\U00002061"},

{"Invisible Times", "\U00002062"},

{"Invisible Separator", "\U00002063"},

{"Invisible Plus", "\U00002064"},

// {"Left-To-Right Isolate", "\U00002066"},

// {"Right-To-Left Isolate", "\U00002067"},

// {"First Strong Isolate", "\U00002068"},

// {"Pop Directional Isolate", "\U00002069"},

// {"Inhibit Symmetric Swapping", "\U0000206a"},

// {"Activate Symmetric Swapping", "\U0000206b"},

// {"Inhibit Arabic Form Shaping", "\U0000206c"},

// {"Activate Arabic Form Shaping", "\U0000206d"},

// {"National Digit Shapes", "\U0000206e"},

}

}

平常反转一个字符串的时候,我是将它一个一个字符的处理

1
2
3
4
5
6
7
8
9
10
    NSString *string = @"一颗赛特123";
    NSLog(@"string1:%@",string);
    NSMutableString *reverseString = [@"" mutableCopy];
    for (NSInteger i = (string.length - 1); i > -1; i--) {
        [reverseString appendString:[NSString stringWithFormat:@"%@", [string substringWithRange:NSMakeRange(i, 1)]]];
    }
    NSLog(@"reverseString:%@",reverseString);

// string1:一颗赛特123
// reverseString:321特赛颗一

那现在就可以这样做了

1
2
3
4
5
6
7
8
9
    NSString *string = @"一颗赛特123";
    NSLog(@"string1:%@",string);
    NSString *tmpString = [NSString stringWithFormat:@"\U0000202E%@",string];
    NSString *reverseString = [tmpString substringFromIndex:1];
    NSLog(@"tmpString:%@ \nreverseString:%@",tmpString,reverseString);

// string1:一颗赛特123
// tmpString:321特赛颗一
// reverseString:一颗赛特123

好吧,字符串里面必须要包含\U0000202E字符,实际项目中如果需要计算长度的话,那这样子做是行不通的。

这种Unicode编码有的时候还是挺有用的,最近在做群聊@功能就用到了\u2005特殊空格字符(听说微信就是这么做的)。
https://github.com/liuwons/wxBot/issues/10