如何在C#中检查包含上标或下标的字符串? [英] How to check a string contains superscript or subscript in C#?
本文介绍了如何在C#中检查包含上标或下标的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查字符串是否包含上标或下标并用相应的文本格式替换。
解决方案
A字符串不包含格式。它可能包含显示为sub / superscript的字符。
这些字符将具有unicode ID。你必须经历它们并自己添加一个映射
即'\ u00B2'= 2,'\ u00B3'= 3
字典< char,char> charmap = new 字典< char,char> {
{' \ u00B2',' 2'},
{' \ u00B3',' 3'},
};
string s abc + ' \ u00B2';
string newS = s.ToCharArray()。选择(c => charMap.ContainKey(c)?charMap [c]:c )。ToArray()。ToString()
// newS ==abc2; 跨度>
Hi,
How to check whether a string contains superscript or subscript and replace it with the corresponding text format.
解决方案
A string does not contain formatting. It may contain characters that appear sub/superscript.
These characters will have unicode ids. You will have to go through them and add a mapping yourself
i.e. '\u00B2' = 2, '\u00B3' = 3
Dictionary<char,char> charmap = new Dictionary<char,char>{ {'\u00B2','2'}, {'\u00B3','3'}, }; string s "abc"+'\u00B2'; string newS = s.ToCharArray().Select(c=>charMap.ContainKey(c)?charMap[c]:c).ToArray().ToString() //newS == "abc2";
这篇关于如何在C#中检查包含上标或下标的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文