Results 1 to 4 of 4

Thread: [RESOLVED]_Last String.split value var[var[0]]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    74

    [RESOLVED]_Last String.split value var[var[0]]

    hi

    I want the msgbox to display sample.ini. For this i need the last value of the splittted array. I know that in another language var[var[0]] would equal to final split, but it does not seem to work in vb. So what equals in vb to final array split?
    vb Code:
    1. Dim vArr As Object
    2.         vArr = Split("C:\NetGame\Common\sample.ini", "\")
    3.         MessageBox.Show(vArr(0))

    Edit: Thanx.
    Last edited by goldenix; Apr 5th, 2008 at 07:54 AM.

    M.V.B. 2008 Express Edition

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Last String.split value var[var[0]]

    Code:
    Dim vArr() as String = "C:\NetGame\Common\sample.ini".Split("\"c)
    MessageBox.Show(vArr(vArr.GetUpperBound(0)))
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Last String.split value var[var[0]]

    This too work..
    Code:
           Dim sArr() As String = "C:\file\sample\sample.ini"
    .Split("\".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
            Dim str As String = sArr(sArr.Length - 1)
            MessageBox.Show(str)
    Visual Studio.net 2010
    If this post is useful, rate it


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

    Re: Last String.split value var[var[0]]

    If you want the file name from a path you shouldn't be using Split or String.Split:
    vb.net Code:
    1. Dim filePath As String = "C:\NetGame\Common\sample.ini"
    2. Dim folderPath As String = IO.Path.GetDirectoryName(filePath)
    3. Dim fileName As String = IO.Path.GetFileName(filePath)
    4.  
    5. MessageBox.Show(folderPath)
    6. MessageBox.Show(fileName)
    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