Remove Last Two Characters in a String

前端 未结 5 819
旧巷少年郎
旧巷少年郎 2020-12-13 03:15

Is there a quick way to remove the last two characters in a String in Swift? I see there is a simple way to remove the last character as clearly noted here. Do you know ho

5条回答
  •  醉酒成梦
    2020-12-13 04:19

    swift 4:

    let str = "Hello, playground"
    let newSTR1 = str.dropLast(3)
    print(newSTR1) 
    
    output: "Hello, playgro"
    
    //---------------//
    
    let str = "Hello, playground"
    let newSTR2 = str.dropFirst(2)
    print(newSTR2)
    
    output: "llo, playground"
    

提交回复
热议问题