Remove last character from string. Swift language

前端 未结 22 1758
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 17:50

    Swift 4.2

    I also delete my last character from String (i.e. UILabel text) in IOS app

    @IBOutlet weak var labelText: UILabel! // Do Connection with UILabel
    
    @IBAction func whenXButtonPress(_ sender: UIButton) { // Do Connection With X Button
    
        labelText.text = String((labelText.text?.dropLast())!) // Delete the last caracter and assign it
    
    }
    

提交回复
热议问题