VB.NET string manipulation

Associate
Joined
12 Mar 2005
Posts
2,021
Location
Scotland
Im sure this can be done easily but i cant get it just now.

I have a string var1 which is a full file path e.g. "C:\Windows\System32\calc.exe"

From this I want to extract "C:\Windows\System32\" and "calc.exe" i.e. split the full string into actual path and file. I can get the file name ok by splitting on "\" and taking the last of the array. But stuck on sticking only the (array - 1) back together. Sure this should be easy and im just missing the obvious, but thats the problem i give to you :)


Any ideas on how i would do this?
 
I don't know any VB.NET syntax but in Java I would iterate over the array but skip the last element and generate a new String from it:

Code:
String[] array = new String[] {"C:", "Windows", "System32", "calc.exe"};
String path = "";

for (int i=0; i < array.length-1; i++) {
	path += array[i] + "\\";
}

I know it's in Java but the structure should be similar in VB.NET, the first line is only there to demonstrate what the array looks like, you will have the array from the string you split.
 
thanks for the quick reply :) thats that bit sorted now. Just to make it work how i want now....

cheers again

Update edit: All working how i want it now, thanks for your help on the file path/names, was really beginning to get at me.
 
Last edited:
Back
Top Bottom