Trim spaces from end of a NSString

前端 未结 14 1170
既然无缘
既然无缘 2020-11-27 09:26

I need to remove spaces from the end of a string. How can I do that? Example: if string is \"Hello \" it must become \"Hello\"

14条回答
  •  Happy的楠姐
    2020-11-27 09:40

    Another solution involves creating mutable string:

    //make mutable string
    NSMutableString *stringToTrim = [@" i needz trim " mutableCopy];
    
    //pass it by reference to CFStringTrimSpace
    CFStringTrimWhiteSpace((__bridge CFMutableStringRef) stringToTrim);
    
    //stringToTrim is now "i needz trim"
    

提交回复
热议问题