Mr. Smith
Mr. Smith

Reputation: 4506

Convert fullwidth to halfwidth

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";

Upvotes: 16

Views: 9040

Answers (1)

petelids
petelids

Reputation: 12815

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.

Upvotes: 27

Related Questions