请尝试专门回答我的问题而不提供替代方法,因为我有一个非常具体的问题,需要这个特殊的解决方案。非常感谢你。
自动我的代码通过VB.NET打开Word,打开文档,找到表,转到单元格,将cells.range.text移动到String变量中,并在For循环中将位置p处的字符比较为< EM>字符串。
我试过字符串: “^ p”,“^ 013”,“U + 00B6”
我的代码:
Dim nextString As String
'For each cell, extract the cell's text.
For p = 17 To word_Rng.Cells.Count
nextString = word_Rng.Cells(p).Range.Text
'For each text, search for structure.
For q = 0 To nextString.Length - 1
If (nextString.Substring(q, 1) = "U+00B6") Then
Exit For
End If
Next
Next
将单元格文本分配给String变量时,结构数据是否会丢失。我过去在VBA中成功搜索过这样的格式标记。
答案 0 :(得分:0)
假设您的字符串包含该字符,您可以使用ChrW
从十六进制值创建相应的字符,并检查该字符:
If nextString.Substring(q, 1) = ChrW(&h00B6) Then
Exit For
End If
<强>更新强>
这是一个完整的例子:
Dim nextString = "This is a test " & ChrW(&H00B6) & " for that char"
Console.WriteLine(nextString)
For q = 0 To nextString.Length - 1
If nextString(q) = ChrW(&H00B6) Then
Console.WriteLine("Found it: {0}", q)
End If
Next
输出:
This is a test ¶ for that char Found it: 15