Results 1 to 4 of 4

Thread: [RESOLVED] [2005] locations in Strings

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Resolved [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!

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
    Last edited by stanav; Apr 12th, 2008 at 08:57 AM.

  3. #3
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2005] locations in Strings

    If you want to retrieve the path to the Desktop, just use this line:

    vb.net Code:
    1. Label1.Text = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop).ToString()

    This will give you the full path including the users name.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width