How to remove whitespace in a string?

后端 未结 13 2190
天涯浪人
天涯浪人 2020-12-17 08:12

I have a string say \"Allentown, pa\"

How to remove the white space in between , and pa using objective c?

13条回答
  •  我在风中等你
    2020-12-17 08:44

    Hi there is the swift version of the solution with extension :

    extension String{
        func deleteSpaces() -> String{
            return self.stringByReplacingOccurrencesOfString(" ", withString: "")
        }
    }
    

    And Just call

    (yourString as! String).deleteSpaces()
    

提交回复
热议问题