Reputation: 3945
var largePictureURL = response.d[i];
//for this example see largePictureURL
largePictureURL = "../uploads/191mapTool_thumb.png_tempLargeFileName=mapTool.png"
largePictureURL will always contain _tempLargeFileName
+ actual file name. Without knowing the actual file name how I can extract _tempLargeFileName
+ actual file name from largePictureURL
?
I know how to do it with indexes but as I said I will be unsure of the name of the file. One thing for sure though I want to extract the remaining part of the string. Please advise
UPDATE @gurvinder372
//thumbNailUrlANDlargeImageUrl = "../uploads/191mapTool_thumb.png_tempLargeFileName=mapTool.png"
var largePictureURL = thumbNailUrlANDlargeImageUrl.split("_tempLargeFileName=")[1];
//largePictureURL = "mapTool.png"
var thumbnailURL = thumbNailUrlANDlargeImageUrl.split("_thumb." + "png")[0];
//thumbnailURL = "../uploads/191mapTool_thumb.png_tempLargeFileName=mapTool.png"
Upvotes: 2
Views: 575
Reputation: 68393
largePictureURL will always contain '_tempLargeFileName' + actual file name.
This is a good enough hint to try this
var fileName = largePictureURL.split( "_tempLargeFileName" )[1]
and if =
is also appended after "_tempLargeFileName"
then modify the same to
var fileName = largePictureURL.split( "_tempLargeFileName=" )[1]
For getting everything before use the 0th index
var before = largePictureURL.split( "_tempLargeFileName=" )[0]
Upvotes: 4
Reputation: 660
You could use substring of the index like this:
var fileName = largePictureURL.substring(largePictureURL.indexOf("_tempLargeFileName"));
That will get you everything to the end of the string, starting with "_tempLargeFileName"
Upvotes: 3