Getting char from a string at a specified index in a visual base

As indicated, how to get char from a string at a specified index in a visual base? I am browsing Google and they do not work:

s(index) , s.Chars(index) , s,Characters(index)

So how to get char at a given index?

+18
source share
3 answers

If s is your string, you can do it like this:

 Mid(s, index, 1) 

Edit based on the comment below.

It seems you need a slightly different approach, which should be simpler. Try as follows:

 Dim character As String 'Integer if for numbers = ActiveDocument.Content.Text - we don't need it character = Activedocument.Characters(index) 
+33
source

Getting one char from a string at a specified index

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

outStr = "b"

+1
source
 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
source

All Articles