- Home /
can't identify slashes
Hi, i'm working with paths in windows.
When i use String.indexOf("/") i get -1 even when there's a slash in the path If i use String.indexOf("\"") happens the same.
Anyone knows how to get the index of a slash using windows paths?
Thanks.
can you post the real code please? as well as the string?
if(myDir.FullName.IndexOf("/") == myDir.FullName.LastIndexOf("/")){ // means there's only 1 slash
print(myDir.FullName.LastIndexOf("/").ToString() + " "+myDir.FullName.IndexOf("/").ToString());
}
This works fine on $$anonymous$$ac, but in windows it prints -1 and -1 for the indexes even when there is and slash in the string.
The string in "C:/"
It's weird: in my PC it works fine (Win XP) - at least with the string "C:/"
Really? i even print the string before saearching the slash. I better take a look at it again, thanks.
The problem is that myDir.FullName is a DirectoryInfo var and it seems not to be trated like a normal string even with the ToString() =/
Answer by Statement · Jan 04, 2012 at 10:38 PM
Try looking for the index of System.IO.Path.DirectorySeparatorChar instead, or "\\" instead of "/".
The value of this field is a slash ("/") on UNIX, and a backslash ("\\") on the Windows and Macintosh operating systems.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Build data path and projects data path on postprocess build. 0 Answers
Can't use BuildFile.path. 0 Answers
how do I change the build path? 1 Answer
pathname slash/backslash 1 Answer