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

前端 未结 11 1900
北恋
北恋 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:36

    let string = "Hello-world"
    if let range = string.range(of: "-") {
    let firstPart = string[(string.startIndex)..

    Output is: Hello

提交回复
热议问题