Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting a String 1

Status
Not open for further replies.

TekSolutions

IS-IT--Management
Jul 15, 2011
71
I have a string that equals a applications path. I need to split that down to the drive only IE (C:\).

I have attempted to use split but I do not need an array.

How can I split this string easily in Visual Basic 2008?
 
You can use substring.

Dim fullPath as String = "C:\Users\Profile\MyProfile\List.txt"
Dim drv as String = ""

drv = fullPath.Substring(0,3) 'Returns "C:\"
drv = fullPath.Substring(0,2) 'Returns "C:"
 
Depending on how you want to use, a better method could be

Imports System.IO

Dim fullPath as String = "C:\Users\Profile\MyProfile\List.txt"
Dim drv as String = ""

drv = Path.GetPathRoot(fullPath) 'Returns "C:\"

 
Thank you RustyChef. I used the first option. Exactly what I wanted
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top