0
- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty;
{
[self dismissViewControllerAnimated:YES completion: nil];
CNLabeledValue *phoneNumberValue = contactProperty.value;
NSString *contactString = [phoneNumberValue valueForKey:@"_stringValue"];
contactString = [contactString stringByReplacingOccurrencesOfString:@"-" withString:@""];
contactString = [contactString stringByReplacingOccurrencesOfString:@" " withString:@""]; // This line of code is not working properly
contactString = [contactString stringByReplacingOccurrencesOfString:@"(" withString:@""];
contactString = [contactString stringByReplacingOccurrencesOfString:@")" withString:@""];
txtRecipient.text = contactString;
}
これは私のコードです。 contactPickerを使用して電話帳から連絡先を選択しています。それから私はそれを文字列変数に格納しています。その後、stringByReplacingOccurrencesOfStringを使用して、文字列値からダッシュ、括弧、およびスペースを削除します。stringByReplacingOccurrencesOfStringは空白で動作しません。つまり、目的のCでは ""です
contactString = [contactString stringByReplacingOccurrencesOfString:@" " withString:@""];
このコード行の後、contactStringは同じままです。つまり、スペースは文字列から削除されませんでした。私もcomponentsSeparatedByString
関数を試しましたが、その戻り値は1文字だけでした。すなわち、
NSArray *components = [dateString componentsSeparatedByString:@" "];
components.lengthは1
を返して、あなたは私の質問を理解してほしいです。文字列からスペースを削除する他の方法はありますか?どんな種類の助けがあっても大丈夫でしょう。ありがとう。
ありがとうございます。出来た。 – Naqi