-1

I have these links in a gallery:

<div id="mygallery">
<ul>
<li><a href="http://farm9.staticflickr.com/8484/824625656895_5e5645636c50d_s.jpg">image 1</a></li>
<li><a href="http://farm9.staticflickr.com/8684/824625654348_5e5546fdcc50d_s.jpg">image 2</a></li>
<li><a href="http://farm9.staticflickr.com/8474/824623123897_f53s3afs6c50d_s.jpg">image 3</a></li>
<li><a href="http://farm9.staticflickr.com/8984/824625656856_5asdfet656655_s.jpg">image 4</a></li>
</ul>
</div>

How can I remove the "_s" from them? So I end up with

<div id="mygallery">
<ul>
<li><a href="http://farm9.staticflickr.com/8484/824625656895_5e5645636c50d.jpg">image 1</a></li>
<li><a href="http://farm9.staticflickr.com/8684/824625654348_5e5546fdcc50d.jpg">image 2</a></li>
<li><a href="http://farm9.staticflickr.com/8474/824623123897_f53s3afs6c50d.jpg">image 3</a></li>
<li><a href="http://farm9.staticflickr.com/8984/824625656856_5asdfet656655.jpg">image 4</a></li>
</ul>
</div>

Live Copy

5
  • 1
    you can use replace() function in javascript Commented Dec 6, 2012 at 9:52
  • 3
    have you tried anything first? Commented Dec 6, 2012 at 9:52
  • You need to specify what options you have available. It could be done using powershell, batch file, vbscript, regular expression replace in a text editor and more besides. What is it that you are trying to do? Is this part of a program, if so what language? This is way too open a question. Commented Dec 6, 2012 at 9:53
  • see this link: [remove part of string][1] [1]: stackoverflow.com/questions/3568921/… Commented Dec 6, 2012 at 9:54
  • here is my fiddle jsfiddle.net/xKyqY/1 Commented Dec 6, 2012 at 10:01

3 Answers 3

2

See update below

I'll make the massive assumption that you have these strings in an array or something.

If so:

var index;
for (index = 0; index < theArray.length; ++index) {
    theArray[index] = theArray[index].replace("_s.jpg", ".jpg");
}

When you give it a string to search for, replace will replace the first occurrence of that string with the replacement string you give it. I did "_s.jpg" (replacing with ".jpg") rather than just "_s" out of paranoia, in case "_s" might appear earlier.


Sure enough, more information completely changes the question.

​$("a").each(function() {
    this.href = this.href.replace("_s.jpg", ".jpg");
});​​​​​​​​​​​​​​​​​​​

Updated Fiddle

Sign up to request clarification or add additional context in comments.

4 Comments

here is My fiddle Sir jsfiddle.net/xKyqY/1
this works, but can it be for that particular div only, it might affect others
@FrancisAlvinTan: Of course it can: $("selector for the div").find("a").each(...). More: api.jquery.com
@FrancisAlvinTan: No worries.
0

Assuing that string is the url.

string = string.replace("_s", "");

Comments

0

May be try with this for all kind of formats

str.replace('_s.', '.');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.