I have a string say:
var currentLabel = "Uploading file... 0%"
This is the initial state when the upload starts and I need to update it as the operation runs. I need to take that 0 and replace it with a new number, however I can’t just get a substring since it will change to 2 digits eventually and the length will change…
If the length was constant I could do:
var newLabel = currentLabel.substring(0, currentLabel.length - 2) + percent + "%";
I’m guessing I need a regular expression or really any other way.
You could probably do it with a combination of
indexOfandsubstring, but a regex does make it simpler:There’s no other numbers in the string, right?
You could also just write the string again .. it would probably be even less expensive than the regex.