It's official: I code better at night.

This is a catch all off topic forum to talk about anything not covered by other sections.
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

It's official: I code better at night.

Post by Red Squirrel »

I just wrote a string vector manipulation function where I pass a vector of strings and then it returns a new vector with only the strings where the start/end match what I specify, with option of specifying if they should be truncated.

So say I pass this list:

test.Add("start_data1_end");
test.Add("more data1");
test.Add("start_this2");
test.Add("data3");
test.Add("tstart_hat4");
test.Add("data5");
test.Add("start_this3_end");


I specify start_ and _end as the parameters the end result should be:

start_data1_end
start_this3_end


If I choose to truncate then it's this:

data1
this3


I compiled, it works first shot. O_o

I'm really loving this late night shift, enabling me to go to bed late.



For those curious this is the function:

Code: Select all

	xVector<string> Parser::FilterIn(xVector<string> data,string start,string end,bool truncate)
	{
		xVector<string> ret;
		
		string tmp;
		bool markasgood;
		
		for(int i=0;data.Get(tmp,i);i++)
		{
			markasgood=false;
			
			if((start.size()<=0 || tmp.find(start,0)==0) && (end.size()<=0 || tmp.find(end,tmp.size()-end.size())!=string::npos))
			{
				markasgood=true;
				
				if(truncate)
				{
					tmp = DeleteOne(tmp,start,0,1);
					tmp = DeleteOne(tmp,end,tmp.size()-end.size(),tmp.size());			
				}			
			}
			
			if(markasgood)ret.Add(tmp);		
		}
		return ret;
	}
Archived topic from AOV, old topic ID:3923, old post ID:25243
Honk if you love Jesus, text if you want to meet Him!
dprantl
Posts: 1048
Joined: Wed Feb 07, 2007 11:41 pm

It's official: I code better at night.

Post by dprantl »

I love vectors. They are the best data storage type ever! Even better than hashtables in most cases.

Archived topic from AOV, old topic ID:3923, old post ID:25247
User avatar
Death
Posts: 7919
Joined: Thu Sep 30, 2004 10:12 pm

It's official: I code better at night.

Post by Death »

dprantl wrote:I love vectors. They are the best data storage type ever! Even better than hashtables in most cases.
Oh God....hashtables. Certainly brings back some bitter memories.

Archived topic from AOV, old topic ID:3923, old post ID:25251
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

It's official: I code better at night.

Post by Red Squirrel »

They can be rather useful but what I normally end up doing is just put a custom type inside a vector instead, sometimes even make a container class to store it in.

Archived topic from AOV, old topic ID:3923, old post ID:25258
Honk if you love Jesus, text if you want to meet Him!
Locked