The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 remove whitespace in string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

havermann

Germany
Posts

Posted - 08/14/2009 :  08:38:43 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.7.0SR2 XP

I have several strings with tons of different whitespace (tabs and blanks). Is there an easy way to remove all whitespace from a string? I tried "TrimLeft" and "remove" without success.

Thanks a lot

BR
Havermann

Regards
Gert

Iris_Bai

China
Posts

Posted - 08/16/2009 :  10:32:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please see the following example:

void remove_whitespace(string str = "ab\tc d e f   g")
{
	str.Replace('\t', ' '); // replace all tabs with black
	
	vector<string> vs;
	str.GetTokens(vs, ' '); // get each token seperated by black 
	
	// append sub string from vs to one string
	string strTemp;
	for(int nn = 0; nn < vs.GetSize(); nn++)
		strTemp += (vs[nn]);
	
	str = strTemp;
	out_str(str);
}


Iris
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 08/17/2009 :  07:29:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
why not just


str.Remove(' ');
str.Remove('\t');


CP
Go to Top of Page

Iris_Bai

China
Posts

Posted - 08/17/2009 :  9:34:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, CP is correct, should use String::Remove.

Iris
Go to Top of Page

havermann

Germany
Posts

Posted - 08/20/2009 :  05:09:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you both, Remove works fine.

BR
Gert

Regards
Gert
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000