Best way to remove unicode Char in text input

Soldato
Joined
27 Mar 2003
Posts
2,710
Hi Guys,

just wondering what the best way is for removing/ stripping out unicode characters. The reason I ask is that it is causing some issues with saving information in a particular way.

Currently I am using this code:

char[] stringconvertor = new char[TextBox1.Text.Length];
string returnstring = "";
stringconvertor = TextBox1.Text.ToCharArray();

for(int loop = 0;loop < TextBox1.Text.Length;loop++)
{

if (stringconvertor[loop] <= 127)
{
returnstring = returnstring+ stringconvertor[loop].ToString();
}

}
TextBox2.Text = returnstring;

now I have found that running this code it takes around 4 minutes to go through about 200,000 characters which is obviously unacceptable for users so is there a better way.
 
i wasn't aware that string concatination was bad. I am still learning c# and although I have learnt a lot I am still doing things that way I probably would when I started out learning other languages such as VB and c++.

I shall try them out and see how much of an effect performance.

edit: well just tried the first example you gave me and it has just flown through a 13million character string in just over 90 seconds. :D
 
Last edited:
Back
Top Bottom