Remove last character from string. Swift language

前端 未结 22 1759
Happy的楠姐
Happy的楠姐 2020-11-30 17:33

How can I remove last character from String variable using Swift? Can\'t find it in documentation.

Here is full example:

var expression = \"45+22\"
e         


        
22条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 18:03

    import UIKit
    
    var str1 = "Hello, playground"
    str1.removeLast()
    print(str1)
    
    var str2 = "Hello, playground"
    str2.removeLast(3)
    print(str2)
    
    var str3 = "Hello, playground"
    str3.removeFirst(2)
    print(str3)
    
    Output:-
    Hello, playgroun
    Hello, playgro
    llo, playground
    

提交回复
热议问题