如何转换超或下标在C#普通文本 [英] How to convert super- or subscript to normal text in C#
本文介绍了如何转换超或下标在C#普通文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了好人URL的蛞蝓发生器。我想平方米转化为M2,但在会为所有标(或下标)的通用方法,而不仅仅是一个简单的替换声明。
I'm writing a slug generator for making nice urls. I'd like to convert m² to m2, but in a generic way that does this for all superscript (or subscript), not just a simple replace statement.
任何想法?
推荐答案
感谢约翰,你让我在正确的轨道上。该代码与我得到它的工作看起来如下:
Thanks Johannes, you set me on the right track. The code with which I got it to work looks 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);
}
我以前试过标准分解,但它所需要的兼容性分解正常工作
I tried the canonical decomposition before, but it needed the compatibility decomposition to work properly.
这篇关于如何转换超或下标在C#普通文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文