could someone help me with stripping text off the end of a string in JS? need to replace text at the end of a given string and then add it back again.
cheers.
| SitePoint Sponsor |
could someone help me with stripping text off the end of a string in JS? need to replace text at the end of a given string and then add it back again.
cheers.
Can I see what code you've created so far?
hey buddy, thanks but i figured it out... using regular expressions. cheers!
Well, glad you found it!![]()
is that the direction you would recommend, or are there better ways?



Regular Expressions are pretty much the way to go, yes.
Of course, that's just my opinion. I could be wrong.
It depends on precisely what you're doing - it might be more efficient to use a simple indexOf() call...
MarcusJT
- former ASP web developer / former SPF "ASP Guru"
- *very* old blog with some useful ASP code
- Please think, Google, and search these forums before posting!
what i'm doing is this... on an event i am taking the .src of an image and suffixing that with "_over.gif" (a separate file), and then on another event, replacing "_over.gif" with ".gif", creating the rollover effect. i am doing this currently with regular expressions.
Well, if you were doing this with a significant number of images in a loop you'd be better off with .indexOf() from an efficiency POV, but using a RegEx for a single string isn't going to make any perceptible difference...
MarcusJT
- former ASP web developer / former SPF "ASP Guru"
- *very* old blog with some useful ASP code
- Please think, Google, and search these forums before posting!
Bookmarks