spewn
Programmer
- May 7, 2001
- 1,034
basically, i know who to check each character using charAt(i), where i equals a progressive number.
but how do i remove individual elements of the string?
any help?
- g
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function removeChar(pos)
{
this = this.substring(0,pos-1) + this.substring(pos, this.length);
}
String.prototype.removeChar = removeChar;
var teststr = "abcdefghij";
teststr.removeChar(5);
alert(teststr) // alerts "abcdfghij"
var str = "hey ";
str = (str.charAt(str.length-1) == " ") ? str.slice(0,str.length-1) : str;
alert (str);
str = str.replace(/\s$/,"");
if (str.charAt(str.length-1)=" ") str=str.slice(0,-2);