i need help. i have vb 2005 and i want to take a string and only use every thing past the last "/" ex. "C:\example\exa mple\THIS-IS-THE-PART-I-WANT.txt"
getting the last part of a string
Collapse
X
-
there is a method called LastIndexOf for a string dataType.
use that to get the index of the required charachter.
Alternatively you may also use the Split method. -
you can call the Split() as / as the delimiter
using UBound you can access the last element of the array formed by split() which is what you want to extract....Comment
-
Split returns an array of strings seperated by the charachters.
get the last array index and that value....which will be what you are looking for
[CODE=cpp]string str = "hello\im\here" ;
int i = str.LastIndexOf ('\');[/CODE]
i will be 9 in this case
cheers
use intellisense and msdn before you start throwing commentsComment
-
Shashi is right
u can use
string str = "C:\example\exa mple\THIS-IS-THE-PART-I-WANT.txt";
int i = str.LastIndexOf ('\');
string s ="";
s= str.substr(i+1, str.length) ;
OUTPUT will be
THIS-IS-THE-PART-I-WANT.txtComment
Comment