How to add a character at a particular index in string in Swift

后端 未结 9 1344
自闭症患者
自闭症患者 2020-12-14 05:30

I have a string like this in Swift:

var stringts:String = \"3022513240\"

If I want to change it to string to something like this: \"(

9条回答
  •  旧巷少年郎
    2020-12-14 06:08

    var phone= "+9945555555"

    var indx = phone.index(phone.startIndex,offsetBy: 4)

    phone.insert("-", at: indx)

    index = phone.index(phone.startIndex, offsetBy: 7)

    phone.insert("-", at: indx)

    //+994-55-55555

提交回复
热议问题