[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:
Dim vArr As Object
vArr = Split("C:\NetGame\Common\sample.ini", "\")
MessageBox.Show(vArr(0))
Edit: Thanx.
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)))
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)
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:
Dim filePath As String = "C:\NetGame\Common\sample.ini"
Dim folderPath As String = IO.Path.GetDirectoryName(filePath)
Dim fileName As String = IO.Path.GetFileName(filePath)
MessageBox.Show(folderPath)
MessageBox.Show(fileName)