I'm looking on how to remove a char from a string for example let's say i have "#22UP0G0YU" i want it to remove the # from it how would i do? I also have a small little other question too about how to make string upper case as well thanks in advance.
1 Answer
To remove a specific char I normally use replace, also good for a set of chars:
var str = '#22UP0G0YU';
var newString = str.replace('#', ''); // result: '22UP0G0YU'
To Uppercase, just use .toUpperCase();
var str = '#22UP0G0yu';
var newString = str.replace('#', '').toUpperCase(); // result: '22UP0G0YU'
3 Comments
Ele
The result of replace is being ignored. Edit your answer:
str = str.replace('#', '');Free TNT
I did that but it didn't really edit the var so i had to assign the replace in another variable. Thx anyway, I'm still looking for how 2 make string uppercase
Rick
@FreeTNT Yeah I should have stated that it needst to be added to the variable, i've updated it, and added the upper case help you needed.
"#22UP0G0YU".slice(1)if#is always first character and"#22UP0G0YU".toUpperCase()for uppercase.