PDA

View Full Version : String.TrimLeft help


melblanc
02-10-2008, 11:11 PM
Hi. I'm trying to get a simple thing to work: get the working path, then remove that string from the path of an image file. But I can't get it to work right. This is my code


working = Folder.GetCurrent();
i_prop = Image.GetProperties("Image1");
i_folder = i_prop.ImageFile;

path = String.TrimLeft(i_folder, working);


The working folder is C:\Builds\My Project\CD_ROOT\
The image file path is C:\Builds\My Project\CD_ROOT\AutoPlay\Images\Image1.png

I expected to get "AutoPlay\Images\Image1.png" out of the TrimLeft action, but instead I get "Image1.png"...? What am I not understanding here? :huh

Thanks!!

RizlaUK
02-11-2008, 06:03 AM
use String.Replace

working = Folder.GetCurrent();
i_prop = Image.GetProperties("Image1");
i_folder = i_prop.ImageFile;

path = String.Replace(i_folder, working,"");

will return "AutoPlay\\Images\\Image1.png"

melblanc
02-11-2008, 11:28 AM
You're a good man! :yes

Thank you very much.

melblanc
02-11-2008, 11:50 AM
But... I get "AutoPlay\Images\Image1.png" and not with the "\\". How could I change this automatically?
can you tell I'm not very good with the String functions? ;)

(Sorry bouble post, but I missed the 15 minute timer...)

TimeSurfer
02-11-2008, 03:08 PM
use another string replace and use this as your substring "\\" and use this as your replace string "\\\\"

melblanc
02-12-2008, 03:46 AM
Makes sense. Thank you!