Results 1 to 6 of 6

Thread: [RESOLVED] Trim and get the string of the character separated by \

  1. #1

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Resolved [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..
    Last edited by shyguyjeff; Apr 7th, 2009 at 01:48 AM.

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    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 "\".
    Last edited by Vectris; Apr 6th, 2009 at 07:40 AM.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    Hyperactive Member su ki's Avatar
    Join Date
    Oct 2007
    Posts
    354

    Re: Trim and get the string of the character separated by \

    vb Code:
    1. Dim  sText As String
    2. sText="C:\MyDocs\Mails\mysave.txt"
    3. Dim sResult As String
    4. sResult= sText.Substring(sText.LastIndexOf("\")+1)
    * If my post helped you, please Rate it
    * If your problem is solved please also mark the thread resolved it is there in right top of page under thread tools
    * Why Rating is useful

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Trim and get the string of the character separated by \

    Thanks you everyone..It helps..Have a nice day..

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