Getting char from string at specified index

后端 未结 3 1273
我寻月下人不归
我寻月下人不归 2020-12-17 10:30

As stated how to get char from string at specified index in the visual basic? I look through google and these do not work:

s(index) , s.Chars(inde

相关标签:
3条回答
  • 2020-12-17 10:52
    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
    
    0 讨论(0)
  • 2020-12-17 11:02

    If s is your string than you could do it this way:

    Mid(s, index, 1)
    

    Edit based on comment below question.

    It seems that you need a bit different approach which should be easier. Try in this way:

    Dim character As String 'Integer if for numbers
    's = ActiveDocument.Content.Text - we don't need it
    character = Activedocument.Characters(index)
    
    0 讨论(0)
  • 2020-12-17 11:08

    Getting one char from string at specified index

    Dim pos As Integer
    Dim outStr As String
    pos = 2 
    Dim outStr As String
    outStr = Left(Mid("abcdef", pos), 1)
    

    outStr="b"

    0 讨论(0)
提交回复
热议问题