user1587011
NSString *trimmedString = [user_ids stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
この文字列メソッドは、文字列の最初と最後のスペースを削除するために使用されます。
これを試してみてくださいそれはあなたが望むものをあなたに与えます:-
NSString *theString = @" Hello this is a long string! ";
NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];
NSArray *parts = [theString componentsSeparatedByCharactersInSet:whitespaces];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];
theString = [filteredArray componentsJoinedByString:@" "];