Swift : How to get the string before a certain character?

前端 未结 11 1898
北恋
北恋 2020-12-24 01:45

How do I get the string before a certain character in swift? The code below is how I did it in Objective C, but can\'t seem to perform the same task in Swift. Any tips or su

11条回答
  •  滥情空心
    2020-12-24 02:31

    Following up on Syed Tariq's answer: If you only want the string before the delimiter (otherwise, you receive an array [String]):

    var token = newstr.components(separatedBy: delimiter).first
    

提交回复
热议问题