Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 20th, 2006, 11:59 AM   #1
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 252
Rep Power: 4 Brent is on a distinguished road
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
Brent is offline   Reply With Quote
Old May 20th, 2006, 12:36 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old May 20th, 2006, 1:55 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
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!
Jessehk is offline   Reply With Quote
Old May 20th, 2006, 2:32 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old May 20th, 2006, 2:57 PM   #5
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
Quote:
Originally Posted by DaWei
How about:
  string theHaystack = "www.mysite.com/post.cgi&post=data";
  string theGoodies = theHaystack.substr ((string::size_type) theHaystack.find ("="));

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!
Jessehk is offline   Reply With Quote
Old May 20th, 2006, 4:11 PM   #6
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 252
Rep Power: 4 Brent is on a distinguished road
thanks for the help, it works great
Brent is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC