LastIndexOf

G

Guest

I am trying to check LastIndexOf "\" in a File Path, if it not there i want
to append a "\"

for some reason it throws error?

int index = filePath.LastIndexOf("\");

Any suggestions...

--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
 
G

Guest

Howdy,


public static string AppendDirSeparator(string path)
{
if (String.IsNullOrEmpty(path))
return String.Empty;

if (path[path.Length - 1] == System.IO.Path.DirectorySeparatorChar)
return path;
else
return path + System.IO.Path.DirectorySeparatorChar;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FileStream 2
reg 1
HashTable 3
Back 1
MVC comparing url value with item in model 2
XML 6
LDAP 1
js 2

Top