如上所述如何从visual basic中的指定索引处获取char?我浏览谷歌这些不起作用:
s(index)
,
s.Chars(index)
,s,Characters(index)
那么如何在指定的索引处获取char?
答案 0 :(得分:27)
如果s
是你的字符串而不是你可以这样做:
Mid(s, index, 1)
根据问题下方的评论修改。
似乎你需要一些不同的方法,这应该更容易。试试这种方式:
Dim character As String 'Integer if for numbers
's = ActiveDocument.Content.Text - we don't need it
character = Activedocument.Characters(index)
答案 1 :(得分:1)
从指定索引处的字符串中获取一个字符
Dim pos As Integer
Dim outStr As String
pos = 2
Dim outStr As String
outStr = Left(Mid("abcdef", pos), 1)
outStr =" B"
答案 2 :(得分:0)
char = split_string_to_char(text)(index)
------
Function split_string_to_char(text) As String()
Dim chars() As String
For char_count = 1 To Len(text)
ReDim Preserve chars(char_count - 1)
chars(char_count - 1) = Mid(text, char_count, 1)
Next
split_string_to_char = chars
End Function