|
-
April 8th, 1999, 02:32 PM
#1
Extracting from strring
Help!
I hope someone can give me some hint on how to do this.
I have a variable
path = "C:\john\1999.01.01(Monday)\15h 35m 54s (Virtual Recorder)"
I need to isolate "Virtual Recorder" into a separate variable. Although Virtual Recorder could have been "LAVAC" or "BANANA". The key is the parentheses.
Thank you in advance
-
April 8th, 1999, 04:08 PM
#2
Re: Extracting from string
First find the last backslash, then look for the parens from that point.
strrchr can do this and, if path is a CString, it probably has some
members that can also.
If path is just a character buffer, once you have the last backslash
calling strtok with a delimiter string of "()" will do it. Remember
that strtok is destructive : it inserts nulls, so if you need to retain
the original string use strtok on a copy of it.
I don't want to just hand you the code because you would learn much
more by wrestling with this kind of string parsing yourself.
-
April 8th, 1999, 04:22 PM
#3
Re: Extracting from strring
Given s is a CString = "C:\john\1999.01.01(Monday)\15h 35m 54s (Virtual Recorder)".
int nOpenParen(s.ReverseFind('('));
if (-1 != nOpenParen) {
int nCloseParen(s.Mid(nOpenParen).Find(')'));
if (-1 != nCloseParen) {
return s.Mid(nOpenParen + 1,
nCloseParen - nOpenParen);
}
}
I *think* the above is right... step through it and watch out for "off-by-one" errors, though.
LA Leonard - Definitive Solutions, Inc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|