...

View Full Version : Can I use Substring in this context?



chelvis
12-15-2006, 04:56 PM
I have a following path name which varies all the time. Say for example the path name may be like these:

/APC101/image2.gif
/CE2_OPEC/image2_s.gif
/EF0OP_12/image3Sm.gif

In the above the first ones are directory names which varies in the code.

I have to remove the first directory and concatenate the image name with another string. So in this case I have to remove from '/' to '/' including the '/'

How can I use substring function to do this? Otherwise is there any other function I can use? I have to incorporate this in C# later.

Arty Effem
12-16-2006, 03:23 AM
I have a following path name which varies all the time. Say for example the path name may be like these:

/APC101/image2.gif
/CE2_OPEC/image2_s.gif
/EF0OP_12/image3Sm.gif

In the above the first ones are directory names which varies in the code.

I have to remove the first directory and concatenate the image name with another string. So in this case I have to remove from '/' to '/' including the '/'

How can I use substring function to do this? Otherwise is there any other function I can use? I have to incorporate this in C# later.
You can use .substring once you get the offset of the last '/', using .lastIndexOf.


<SCRIPT type='text/javascript'>
String.prototype.replacePath=function(newPath)
{
return newPath+this.replace(/^.*\/([^\/]*)$/, "$1");
}

alert("/EF0OP_12/image3Sm.gif".replacePath('/my/new/path/'));
</SCRIPT>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum