how to get rid of heading and trailing white spaces from NSString

前端 未结 2 759
北荒
北荒 2020-12-19 08:05

My NSString is like this:

NSString *myString =  
(  
“\\n \\n 24 K CLUB”,  
“\\n \\n 3 DOLLAR CAFE”,  
“\\n \\n A PEACH OF A PARTY”,  
“\\n \\n A ROYAL AFFAI         


        
相关标签:
2条回答
  • 2020-12-19 08:49

    Your initial declaration of myString is declaring an NSArray, not a NSString. Your calls to stringByReplacingstringByReplacingOccurrencesOfString: withString: should work on the individual NSStrings. Either iterate the array yourself (see here) to trim the strings, or use makeObjectsPerformSelector: (see here) to handle it.

    0 讨论(0)
  • 2020-12-19 08:54

    How about stringByTrimmingCharactersInSet: method? By stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet], it can remove both ends of whitespace and newline characters.

    0 讨论(0)
提交回复
热议问题