[RESOLVED] Trim and get the string of the character separated by \
Hello everyone. I am having a problem on getting the last string of the character separated by a \. It looks like this.
this is the character before:
C:\MyDocs\Mails\mysave.txt
I want this to get the mysave.txt. How can I do that? Thank you everyone..
Re: Trim and get the string of the character separated by \
If it will always be in that format, like a file, you can use:
Code:
My.Computer.FileSystem.GetFileInfo("C:\MyDocs\Mails\mysave.txt").Name
If your not sure, you can use:
Code:
Dim theString As String = "C:\MyDocs\Mails\mysave.txt"
Dim theIndex As Integer = theString.LastIndexOf("\") + 1
theString = theString.Substring(theIndex, theString.Length - theIndex)
However that will rely on the fact that the text you want always comes after the last "\".
Re: Trim and get the string of the character separated by \
vb Code:
Dim sText As String
sText="C:\MyDocs\Mails\mysave.txt"
Dim sResult As String
sResult= sText.Substring(sText.LastIndexOf("\")+1)
Re: Trim and get the string of the character separated by \
Code:
Dim aPath As String = "C:\MyDocs\Mails\mysave.txt"
Dim theFileName As String = IO.Path.GetFileName(aPath)
Re: Trim and get the string of the character separated by \
Hey,
I have to go with dbasnett on this one, the Path Class has a number of methods that make getting information about the Path of a File very easy, have a look at the following:
http://msdn.microsoft.com/en-us/libr...h_members.aspx
Very useful!!
Gary
Re: Trim and get the string of the character separated by \
Thanks you everyone..It helps..Have a nice day..