0

I want to delete 5 characters in a string, so I plan to use a loop to do that. but actually code not report any error, but still, I can only delete one character

var i = Int()
repeat {
    proxy.deleteBackward(); 
    i = i+1
} while i<5
 
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
Dennislay
  • 1
  • 3
  • As far as i understood u want to remove the last 5 characters of a string. u can use ```your_string.dropLast(5)``` – udi Jul 07 '22 at 06:40
  • Sure, I want to delete the last 5 character, thanks to clarify that for me1 – Dennislay Jul 08 '22 at 06:39

1 Answers1

0

if you want to remove last 5 characters of your string , use

myString.dropLast(5) 

if you want to run your deleteBackward() method 5 times, use like this

var i = 0
        while i<5 {
            proxy.deleteBackward()
           i += 1
        }
Vikas saini
  • 648
  • 1
  • 17