0

Hi,

Can anyone tell me how I would remove characters from a string if they are present?

For example lets say I wanted to remove c:/fakepath/ from the string c:/fakepath/DSF102.jpg and just leave the DSF102.jpg how would I got about this?

I got close but I need help.

Thanks in advance

Wayne

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Waynef
0

To Accomplish this , you should use the string method replace()
which takes 2 arguments the portion you want to replace and what you want to replace it with

so , in your case you need to replace the whole string except the image name with nothing in the main string
so the code will be like this

var string = "c:/fakepath/DSF102.jpg";
var newString = string.replace ("c:/fakepath/","");
// now the variable newString holds the value DSF102.jpg 
// To Test it
alert(newString);

Hope this helps =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.