1
我目前正在在這樣的字符串的一部分;撇號單字符比較問題
if (thisChar == 'a')
[self a];
else if (thisChar == 'b')
[self b];
else if (thisChar == 'c')
[self c];
.........
else if (thisChar == '0')
[self zero];
else if (thisChar == '1')
[self one];
else if (thisChar == '2')
[self two];
else if (thisChar == '3')
[self three];
.........
else if (thisChar == '.')
[self period];
else if (thisChar == ',')
[self comma];
else if (thisChar == '?')
[self qmark];
的問題,但出現時,我來到
else if (thisChar == ''')
[self three];
我要的是'(撇號)的跡象,但它不會讓我這樣做。我知道原因,但我不知道它的方式。這樣做會有幫助嗎?
NSString *apostropheString = [[NSString alloc] initWithFormat:@"'"];
unichar apostrophe = [apostropheString characterAtIndex:0];
我可以使用isEqualToString嗎?
if ([apostrophe isEqualToString: thisChar])
任何幫助將不勝感激!
我找到了解決辦法:
1)。創建與單個字符是一個撇號
NSString *apostropheString = [[NSString alloc] initWithFormat:@"'"];
2)NNString。得到它把它轉換爲一個名爲「應用程序」單字符,因爲它是零索引,並且只有一個字符的索引爲0
unichar app = [apostropheString characterAtIndex:0];
3)。然後我說,如果「thisChar」等於「應用程序」運行「QMARK」
else if (thisChar == app)
[self qmark];
我希望這有助於爲同樣的問題任何人!
別擔心,我已經找到解決的辦法!查看信息編輯。 – 2011-01-30 20:22:11
你不能使用`'''`? – Gabe 2011-01-30 20:24:52