how do i take a .src (document.images[0].src =, for instance) and change one character in it? i'm working with an array which contains filenames, either 8 or 9 characters in length (keyword+#val+sub-val+".jpg") i want to change the character in the sub-val. ex: pict1b.jpg - change to pict1c.jpg, -or-, img3b.jpg - change to img3c.jpg... change that "b" to a "c" there will be no other instances of the letter "b" or "c" in these filenames; how do i take the .src and use indexof and replace to make the b into a c? i'm not quite intermediate, yet, so go easy on me! heeh =b
Is all the text contained withing one document? If yes, use notepad 'control+h'... I think this is what you are asking...
er, user clicks an image in webpage, new window opens, displays that image; how can i take that image's src and change one character in it? i would like to know the javascript to include to take document.images[0].src and subtract the "b" and replace it with a "c", the "b" will be the 5th or 6th character in every src, and there will be no other uses of "b" or "c" in the filenames. i have pict1a.jpg, pict1b.jpg, pict1c.jpg for each picture, "a" is thumbnail, "b" is slideshow version, "c" is the fullsize one; i don't want to make a new array, i want to change the "b" to a "c" in the filename.
Once you know the index of the character you want to replace, use one of the substring functions (substr, substring or slice) to recompose the string out of three parts - the part before the character, the alternative character and the part after: var s = "abc5def"; var i = s.indexOf("5"); new String().concat(s.substring(0,i), "0", s.substring(i+1,s.length)); If you want to go fancy style, you can use regex. For example, the following code will replace numbers in the middle of the string with a dot: "abc123def".replace(new RegExp("([a-z]+)[0-9]+([a-z]+)"), f); function f(p1, p2, p3, p4, p5) { return p2 + "." + p3; } This won't work in older browsers, though - this form of replace wasn't in the first JS versions. J.D.
you da man, i thought i was on the right track, well, i was/am, here! so it's indexof, substr, and concat... thanks greatly!