Getting char from string at specified index Getting char from string at specified index vba vba

Getting char from string at specified index


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 itcharacter = Activedocument.Characters(index)


Getting one char from string at specified index

Dim pos As IntegerDim outStr As Stringpos = 2 Dim outStr As StringoutStr = Left(Mid("abcdef", pos), 1)

outStr="b"


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 = charsEnd Function