problem with string.Trim();

J

Jeroen Ceuppens

Hi, I want to parse a string like "abc abc erer" to "abcabcerer"

=> change white spaces, ..... into nullstring

I tried this code:

char[] trimChars={' ','<','>'};

test=test.Trim(trimChars);

but I don't do what I want :(((( (it doesn't change anything)
Can anybody help?

Thx
Jc
 
K

Kevin Hutchison

"String.Trim Method (Char[]) - Removes all occurrences of a set of
characters specified in an array from the *beginning and end* of this
instance."

Use a Regular Expression.

Ex.

using System.Text;

void foo()
{
RegularExpressions.Regex regTest = new RegularExpressions.Regex(
@"[\s,<>]" );
string test = "abc abc erer<a,b>c";
test = regTest.Replace( test, "" );
}
- K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top