0

I have some characters like: TD

Which is obviously different from "TD". How can I convert TD to TD (or similar characters) in C#?

It seems that the TD happens when you try to input normal characters with a japanese (or other language) keyboard.

Edit: Duplicate has the same problem, but is not C#. See my answer for a C# duplicate that solved my problem.

Manuel Hoffmann
  • 539
  • 1
  • 7
  • 23
  • Possible duplicate of [how to transform japanese english character to normal english character?](http://stackoverflow.com/questions/14776998/how-to-transform-japanese-english-character-to-normal-english-character) – Heretic Monkey May 31 '16 at 17:48
  • You can detect the input character set (i.e., Japanese character sets, Korean character sets, etc.) through the `GetCharsInRange` as explained in this [StackOverflow answer](http://stackoverflow.com/a/15806958/5209610). Do you think that the ASCII output of Japanese characters (i.e., UTF-8 encoding) is really meaningful? What information would "TD" give you? The problem is slightly easier if you're working with Latin scripts with accents - in [this answer](http://stackoverflow.com/a/13769669/5209610) you'll see how you replace accented character with their "un-accented" versions. – Vladislav Martin May 31 '16 at 18:11
  • From the title and a glance, it is indeed a duplicate. @VladislavMartin I need to compare if the found string is == "TD". But some parts of what i read are TD and some are TD. That's why I need the conversion. – Manuel Hoffmann May 31 '16 at 18:52

1 Answers1

1

Even though the duplicate question was indeed my problem, what solved my problem was another answer to a different duplicate: https://stackoverflow.com/a/25149897/2026623

Using the String.Normalize method, I was able to convert the characters to their half-width counterparts.

Community
  • 1
  • 1
Manuel Hoffmann
  • 539
  • 1
  • 7
  • 23
  • It is worth mentioning that the difference between TD and TD is not at all obvious in some browsers (or is it other OS's?). All I know is that I couldn't tell a difference between the characters in this question while viewing it on a Ubuntu machine in Firefox, but I CAN tell the difference very clearly now that I am looking at it on a Windows machine in Chrome. Now the character formatting problem is way more obvious to me :) – Vladislav Martin Jun 01 '16 at 23:17
  • I tested on some different browsers (windows only) but even though the appearances of the full-width characters are different in each browser, you can still see the difference compared to the half-width versions. So it should be an OS-thing. – Manuel Hoffmann Jun 02 '16 at 06:33