0

iOS 7 sdk に更新したばかりで、文字列の文字間の空白を削除/置換して、ABAddressBook から数値を取得したいと考えています。

以下の " " を "" に置き換えるコードを使用してみましたが、このコードは ios7 SDK では機能しないようです。ちなみに、iOS 6 SDK では正常に機能します。

NSString *TrimmedNumberField = [self.numberField.text 
stringByReplacingOccurrencesOfString:@" " withString:@""];

IOS 7でそれを行うことができる他の方法はありますか?

編集:

試しているのは電話番号タイプです。

入力:"+65 12 345 6789"

NSLog から得た出力は" 12 345 6789"

NSDictionary に追加して NSLog で表示すると、フルストップに等しくない「中央のドット」に似た \u00a0 の UNIX コード表現が含まれているように見えることに気付きました。

前もって感謝します。

4

4 に答える 4

0

文字列をループして、空白がある限り削除できます

NSString *someString = @"A string with   multiple spaces and    other whitespace.";

NSMutableString *mutableCopy = [someString mutableCopy];

// get first occurance of whitespace
NSRange range = [mutableCopy rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]];

// If there is a match for the whitespace ...
while (range.location != NSNotFound) {
    // ... delete it
    [mutableCopy deleteCharactersInRange:range];
    // and get the next whitespace
    range = [mutableCopy rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]];
}

// no more whitespace. You can get back to an immutable string
someString = [mutableCopy copy];

上記の文字列の結果はAstringwithmultiplespacesandotherwhitespace.

于 2013-10-03T07:35:34.940 に答える