1

I want to make a little gallery and add next/previous buttons. I managed to trim down the urls of the pictures to something like this : 30052010/30052010001 . So the picture is 30052010001.jpg and the next one is 30052010002.jpg .However how can i remove the first part of the string(the folder name) and the last digits from the end of the string so that i can auto-increment a variable and change to the next picture ? Thanks.

3
  • I don't thing jQuery has a function for that, and a plugin would just do a string.split(char) Commented Jun 25, 2010 at 13:21
  • As other people have impled, there is no need to use jQuery for this functionality - even if you're usuing it for other things. There isn't anything specific in the jQuery library for this kind of stuff, because it's built into the JavaScript language already. As powerful as it is, don't try to use jQuery for everything. Commented Jun 25, 2010 at 13:42
  • i understand and i know that this method is far more complicated but i cannot change the php code so its my only option Commented Jun 25, 2010 at 20:06

3 Answers 3

4

You can do it with only Javascript like this:

var x = "30052010/30052010001";
y = x.split('/');
alert(y[1]+'.jpg');
Sign up to request clarification or add additional context in comments.

Comments

2

You can use split function

Comments

2
var filename = '30052010/30052010001';
var parts = filename.split('/');
var newFilename= (parts[0] + "/" + ++ (parts[1])); // '30052010/30052010002'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.