Digital Point Forums
Wire Transfer

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Jun 5th 2005, 5:55 pm
somebody somebody is offline
Peon
 
Join Date: Jun 2005
Posts: 4
somebody is on a distinguished road
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
Reply With Quote
  #2  
Old Jun 5th 2005, 6:22 pm
NewComputer's Avatar
NewComputer NewComputer is offline
of the Nightfall
 
Join Date: May 2004
Location: Canada
Posts: 1,993
NewComputer will become famous soon enoughNewComputer will become famous soon enough
Is all the text contained withing one document? If yes, use notepad 'control+h'... I think this is what you are asking...
Reply With Quote
  #3  
Old Jun 5th 2005, 8:53 pm
somebody somebody is offline
Peon
 
Join Date: Jun 2005
Posts: 4
somebody is on a distinguished road
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.
Reply With Quote
  #4  
Old Jun 5th 2005, 8:55 pm
NewComputer's Avatar
NewComputer NewComputer is offline
of the Nightfall
 
Join Date: May 2004
Location: Canada
Posts: 1,993
NewComputer will become famous soon enoughNewComputer will become famous soon enough
Yea, that sounds like J.D. territory. I am sure if JD is around, he can chime...
Reply With Quote
  #5  
Old Jun 6th 2005, 5:43 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
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.
Reply With Quote
  #6  
Old Jun 6th 2005, 4:54 pm
somebody somebody is offline
Peon
 
Join Date: Jun 2005
Posts: 4
somebody is on a distinguished road
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!
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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


All times are GMT -8. The time now is 11:46 pm.