NSString にその部分文字列が含まれていると仮定して、NSString から特定の部分文字列を除外する方法を知りたいです。
例えば:
元の文字列: "これは文字列ですが、これらの単語は省略してください。"
省略する部分文字列: " but these words should be入ります".
結果文字列: 「これは文字列です。」
よろしくお願いします、iLyrical。
NSString にその部分文字列が含まれていると仮定して、NSString から特定の部分文字列を除外する方法を知りたいです。
例えば:
元の文字列: "これは文字列ですが、これらの単語は省略してください。"
省略する部分文字列: " but these words should be入ります".
結果文字列: 「これは文字列です。」
よろしくお願いします、iLyrical。
NSString *originalString = @"This is a string but these words should be omitted.";
NSString *substringToOmit = @" but these words should be omitted";
NSString *resultString = [originalString stringByReplacingOccurencesOfString:substringToOmit
withString:@""];
を参照してくださいNSString
。stringByReplacingOccurrencesOfString:withString:
末尾の空白を でトリミングすることもできますstringByTrimmingCharactersInSet:
。