Is there any way to convert unicode values to ASCII?
相关问题
- WCF Web Service: Upload a file, Process that file,
- regex pattern for a range and above 127
- Exception “error MSB3024: Could not copy the file…
- How to properly unit test calling UI method on ano
- Serializing a List<> exported as an ICollection
相关文章
- .NET - how to make a class such that only one othe
- Xdocument does not print declaration
- ~1 second TcpListener Pending()/AcceptTcpClient()
- Representing C#3 code as an Abstract Syntax Tree i
- C# Batch plot application (PrintServer & PrintQueu
- Running devenv against a .vdproj at the command li
- Removing line breaks using C#
- Value does not fall within the expected range
To simply strip the accents from unicode characters you can use something like:
Technically, yes you can by using
Encoding.ASCII
.Example (from byte[] to ASCII):
Just remember Unicode a much larger standard than Ascii and there will be characters that simply cannot be correctly encoded. Have a look here for tables and a little more information on the two encodings.
Well, seeing as how there's some 100,000+ unicode characters and only 128 ASCII characters, a 1-1 mapping is obviously impossible.
You can use the
Encoding.ASCII
object to get the ASCII byte values from a Unicode string, though.This workaround might better suit your needs. It strips the unicode chars from a string and only keeps the ASCII chars.
Please note that the 2nd "space" in the character input string is the char with ASCII value 255
You CAN'T convert from Unicode to ASCII. Almost every character in Unicode cannot be expressed in ASCII, and those that can be expressed have exactly the same codepoints in ASCII as in UTF-8, which is probably what you have. Almost the only thing you can do that is even close to the right thing is to discard all characters above codepoint 128, and even that is very likely nowhere near what your requirements say. (The other possibility is to simplify accented or umlauted letters to make more than 128 characters 'nearly' expressible, but that still doesn't even begin to actually cover Unicode.)