如何在VB.Net中替换字符串中的上标字符



我必须解析一个值为m²和100in²的文本文件。在运行代码时,我正在测试这些代码的字符串。测试失败是因为";有时";它将字符视为�'或100英寸�'.当我第一次用测试字符串中的上标写它时;如果行。包含("100in²"(然后"它工作了几次,但后来它卡住了,字符串在代码中不再以相同的方式表示,所以测试看不到²�.那么,我如何测试字符串,看看它是否以一致和防爆炸的方式包含上标?

检查的asc代码�,然后使用此asc代码解析您的文件。

由于您还没有显示任何代码,因此很难给出一个好的答案。以下是一些可能引发一些想法的代码。

Debug.WriteLine("")
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
path = IO.Path.Combine(path, "test.txt")
'round trip text to file
Dim s As String = "⁰¹²⁴m² and 100in²"
Dim t As String = s
IO.File.WriteAllText(path, t)
t = IO.File.ReadAllText(path)
If t <> s Then Stop
For Each c As Char In s
Debug.WriteLine("'  {0} {1}", c, AscW(c))
Next
' CH  Dec. code
'  ⁰ 8304
'  ¹ 185
'  ² 178
'  ⁴ 8308
'  m 109
'  ² 178
'    32
'  a 97
'  n 110
'  d 100
'    32
'  1 49
'  0 48
'  0 48
'  i 105
'  n 110
'  ² 178
Dim superSCRs As String = "⁰¹²³⁴"
For Each super As Char In superSCRs
If s.Contains(super) Then
Stop
End If
Next

最新更新