Here is the sample path, assuming the format is fixed
For the 4th image, the path is ‘demo/medium/Web081112_P004_medium.jpg‘
so if the image is the 100 th ,then
‘demo/medium/Web081112_P100_medium.jpg ‘
Is there any way to get the number in this format, I have thought about using reg exp? But it may cause a problem because I may retrieve 004 instead of 4, how to fix this? Thanks
This answer is based on the message in the original question
sample path, assuming the format is fixed
If the string is not going to change then you can use split:
Note remember the parseInt needs the radix 10 to remove the leading 0s which would otherwise make the number OCTAL
Also note that splitting on
_Pwill (as mentioned by Cerbrus) get the the string004_medium.jpgwhich still works with parseInt because parseInt will ignore trailing non-numeric characters