![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Highly Adaptive Penguin
Join Date: May 2005
Location: United States
Posts: 252
Rep Power: 4
![]() |
how to parse?
i was wondering how i would break this down into three 2 parts:
www.mysite.com/post.cgi&post=data i want to be able to take 'data' from the rest of the string and use it. i am using open watcom compiler on windows xp brent |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
What is a "three 2 part"? In the absence of a clear question, I would say find the "=" and take everything beyond. (Polishes loaner ball bearing while crystal is in the shop.)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
I wrote a split function to do this very thing. Enjoy
![]()
//split takes a string of words and returns a vector of words, seperated
//by a character specificed in "splitPoint". eg: "Hello there!" = a vector containing "hello" and "there!"
std::vector<std::string> split(const std::string &text, char splitPoint)
{
std::string input(text);
std::string subString;
std::vector<std::string> words;
int count = 1;
int a = 0;
for(int x = 0; x < text.size(); x++) {
subString = "";
if(text[x] == splitPoint || count == 1) {
a = (count == 1 ? x : x + 1);
++count;
while(1) {
if(text[a] == splitPoint || a == text.size())
break;
subString += text[a++];
}
words.push_back(subString);
}
subString = "";
}
return words;
}
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
How about:
string theHaystack = "www.mysite.com/post.cgi&post=data";
string theGoodies = theHaystack.substr ((string::size_type) theHaystack.find ("="));
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
Quote:
Of course that would work too (and much more simply, efficiently, and cleanly). I just wanted to show off my split() function. ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#6 |
|
Highly Adaptive Penguin
Join Date: May 2005
Location: United States
Posts: 252
Rep Power: 4
![]() |
thanks for the help, it works great
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|