473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getting the last part of a string

59
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\example\THIS-IS-THE-PART-I-WANT.txt"
Jan 6 '08 #1
6 1199
Shashi Sadasivan
1,435 Expert 1GB
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.
Jan 6 '08 #2
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....
Jan 6 '08 #3
raids51
59
first i just dont understand what ur talkin about with the lastindexof part and second i could use split but there is more then one "/" in the string any more ideas/details
Jan 6 '08 #4
Shashi Sadasivan
1,435 Expert 1GB
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

Expand|Select|Wrap|Line Numbers
  1. string str = "hello\im\here";
  2. int i = str.LastIndexOf('\');
i will be 9 in this case

cheers
use intellisense and msdn before you start throwing comments
Jan 6 '08 #5
kunal pawar
297 100+
Shashi is right
u can use

string str = "C:\example\example\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.txt
Jan 7 '08 #6
Plater
7,872 Expert 4TB
Another option is, if you are using this to only find filenames from a full file path, is to use the FileInfo class and use the .Name property to get the filename.
Jan 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
5
by: SimonH | last post by:
Hi all, I'm having problems identifying how to get the last directoy in a path string. For example, in the Path 'C:\dir1\dir2\dir3' I want to be able to get the name dir3 I've tried the...
9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
36
by: Lindie | last post by:
The more I read the more confused I get. Too much on dates calulations in the groups. I need to know how often a book has been loaned out over the past year- 52 weeks. My table has Book...
3
by: Ilja Booij | last post by:
Hi all, I have some trouble with the following: I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM, where the...
3
by: Adam Tibi | last post by:
Hi, Is there a way of getting the domain name of tghe currently executing site, I tried using this silly code: public static string GetDomainName() { string serverName =...
7
by: Aaron Gray | last post by:
I put together the following code to get the href's parameters :- function GetParameters() { var arg = new Object(); var href = document.location.href; if ( href.indexOf( "?") != -1) { var...
6
by: rbutlerjr | last post by:
Hi, I've racked my brain for the last few hours trying to figure this one out. I have an array of language strings such as : $lang = array(); $lang = 'hello'; $lang = 'goodbye'; $lang = '1st';...
3
by: MDCdeveloper | last post by:
Hello all, and thank you in advance for any feedback/help you might post. I need help getting a web page element id out of a string variable to be used within my c# code behind page. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.