In C#, how do I convert a string that's using fullwidth form characters into halfwidth form characters?
For example, given userInput
below, I want to convert Stackoverflow
to Stackoverflow
:
string userInput= "Stackoverflow";
//string userInput= "Stackoverflow";
You can use the string.Normalize()
method:
string userInput = "Stackoverflow";
string result = userInput.Normalize(NormalizationForm.FormKC);
//result = "Stackoverflow"
See example on DotNetFiddle.
More information on the Normalization Forms can be found on unicode.org.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With