Trim spaces from end of a NSString

前端 未结 14 1201
既然无缘
既然无缘 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条回答
  •  没有蜡笔的小新
    2020-11-27 09:59

    In Swift

    To trim space & newline from both side of the String:

    var url: String = "\n   http://example.com/xyz.mp4   "
    var trimmedUrl: String = url.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
    

提交回复
热议问题