How to convert super or index to plain text in C #

I am writing a bullet generator to create good urls. I would like to convert m² to m2, but in a general way that does this for all superscripts (or indices), and not just for a simple replacement.

Any ideas?

+6
c # subscript slug superscript
Apr 20 2018-10-10T00:
source share
2 answers

Thanks, Johannes, you set me on the right track. The code I worked with is as follows:

public string ConvertSuperscript(string value) { string stringFormKd = value.Normalize(NormalizationForm.FormKD); StringBuilder stringBuilder = new StringBuilder(); foreach (char character in stringFormKd) { UnicodeCategory unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(character); if (unicodeCategory != UnicodeCategory.NonSpacingMark) { stringBuilder.Append(character); } } return stringBuilder.ToString().Normalize(NormalizationForm.FormKC); } 

Previously, I tried canonical decomposition, but for the decomposition of compatibility to work correctly, it needed to work.

+4
Apr 20 '10 at 14:18
source share

If your string is specified in the URL, I assume that this is some plain unformatted text in the form of Unicode characters (unlike an MS Word document, for example). In unicode, you can only have certain characters as superscript or subscript . There are not many, and a simple switch statement will do this.

If you are trying to convert formatted text that can contain all kinds of characters in the form of superscript or subscript, this means that they are not represented directly as unicode, and this will greatly depend on the text format. If yes, please give more information in the question.

+1
Apr 20 '10 at 8:14
source share



All Articles