encoding - How to convert (transliterate) a string from utf8 to ASCII (single byte) in c#? -


I have a string object

"with multiple letters and even special characters"

I am trying to use

  UTF8Encoding utf8 = new UTF8Encoding (); ASCIIEncoding ascii = new ASCIIEncoding ();  

Objects to convert that string to ascii, would I ask someone to bring some light into this simple task, which is hunting me in the afternoon.

EDIT 1: Some of the special efforts we are trying to accomplish are getting rid of special letters such as apostrophes. The code I posted as an answer below will not take care of it, basically

will O'Brien become? Brian is one of the special apostrophes

This was in response to your second question , It seems that it has been removed .... this thing is still standing.

It seems like this move where is happening.

.net works fine with Unicode, (or left on the default) to start to believe.

My Estimate is that your received app can not handle it, so, I'll probably use one with string. Empty:

  using System.Text; String input string = GetInput (); Var encoder = ASCII encoding Gate encoder (); Encoder Fallback = New Encoder ReplacementFlowback (string.optim); Byte [] bAsciiString = encoder.getbits (inputstring); Can do something with // bytes ... // as the file is as file. WrititeAllBytes (FILE_NAME, bAsciiString); // Return to the "clean" string string cleanString = ASCIIEncoding.GetString (bAsciiString); // Because degrading bytes have been removed, you can use the assurance with the default encoding. Erequal (Cleanstring, Default. Getstring (BASCIstring));  

Of course, in the olden days, we just loop and remove any character ... well, at least among us in America;)

< / Div>

Comments