2012-04-27 99 views
3

我面臨一個奇怪的問題。 我有一個UITextField和一個NSString,我想使用isEqualtoString方法進行比較。 只要字符串不包括德語,如Ä,Ö,Ü一切正常,但如果他們這樣做不再工作。 NSLog正確地發出了Umlaute字符串。比較NSStrings與Ä,Ö,Ü

NSLog([currentAnswer lowercaseString]); 
NSLog([[self.antwortTextField text]lowercaseString]); 

if ([[currentAnswer lowercaseString] isEqualToString:[[self.antwortTextField text]lowercaseString]]) {......} 

是否必須以某種方式格式化字符串?這個問題讓我瘋狂!

+0

可能重複(http://stackoverflow.com/ questions/2492379/sort-an-array-with-special-characters-iphone) – 2012-04-27 17:16:40

回答

4

您可以使用先進的NSString比較方法,如:

- (NSComparisonResult)compare:(NSString *)aString 
         options:(NSStringCompareOptions)mask 
         range:(NSRange)range 
         locale:(id)locale 

,然後指定高級選項。具體的選項,你可能感興趣的:的[排序有特殊字符數組 - iPhone]

  • NSCaseInsensitiveSearch
  • NSDiacriticInsensitiveSearch
  • NSWidthInsensitiveSearch
+0

對不起,我對Objective-C比較陌生。我會怎麼做?我完全不知道爲什麼它不起作用。這不像德語是一種古老的語言或任何東西;-) – JohannesRu 2012-04-27 16:22:56

+1

也許'bool isEqual = NSOrderedSame == [str1比較:str2選項:NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch];',或者某些選項的組合。原因可能是語言,或者它可能是語言環境,或編碼或... – justin 2012-04-27 16:28:03

+0

好吧我知道了,非常感謝你! – JohannesRu 2012-04-27 16:42:01

相關問題