![]() |
|
|
|
||||||||||
![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
want to alter one character in an image src
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 |
|
#2
|
||||
|
||||
|
Is all the text contained withing one document? If yes, use notepad 'control+h'... I think this is what you are asking...
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
Yea, that sounds like J.D. territory. I am sure if JD is around, he can chime...
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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! |
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Image ads vs text ads - what is better in $ revenue | hans | AdSense | 18 | May 17th 2009 9:42 am |
| Checking source codes of image, audio and video files | onauc | Programming | 0 | Feb 21st 2005 5:34 pm |
| Centering an Image within a Block Element | robert_neville | CSS | 1 | Feb 12th 2005 7:13 pm |
| Setting up a linked image series | Don Key | HTML & Website Design | 4 | Nov 23rd 2004 1:58 pm |
| Image / NEWS Search Engine Optimization | ! ! | Suggestions & Feedback | 3 | Apr 9th 2004 8:05 am |