[RESOLVED] [2005] locations in Strings
Hello in one of my programs i have a textbox that retrieves the name the users computer is registered to. There is one problem with it, it retrieves the value /Alex Torthor (made up name) with a " / " before the name. I know it's possible because i read it in a book somwhere i just forget...
How do i retrieve all the text that comes after the first character the " / " ?
also while you are replying how do you retrieve the text value that comes between two " / " to retrieve a value
For example i want to know the users name to complete this path:
C:/documents and settings/users name/desktop/MyFileorFolder
or i want a label to just show /MyFileorFolder not the stuff that comes before it. But i want it to still have the value of:
C:/documents and settings/users name/desktop
Please Help!:cool:
Re: [2005] locations in Strings
There are a couple of ways to do it, one is to string.split to split the string at the "/" charater and take the 2nd element of the returned array. The other option is to use string.substring... I think the 2nd option is cleaner in this case
Code:
Dim userName As String = yourstring.Substring(yourstring.IndexOf("/") + 1)
For the 2nd question, you can use System.IO.Path.GetFileName("put the path here") to get the name of the folder. You then assign it to your label.text property. You can save the full path in your label.Tag property
Re: [2005] locations in Strings
If you want to retrieve the path to the Desktop, just use this line:
vb.net Code:
Label1.Text = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop).ToString()
This will give you the full path including the users name.
Re: [2005] locations in Strings
You should use the Path class to manipulate file and folder paths. The GetFileName method will get the substring after the last delimiter and the GetDirectoryName will get the bit before it.