As stated how to get char from string at specified index in VBA (Visual Basic for Applications)? I searched Google and these do not work:
s(index)
,
s.Chars(index)
,s,Characters(index)
So how to get char at specified index?
You can get the character at a particular index within a string by invoking the charAt() accessor method. The index of the first character is 0, while the index of the last character is length()-1 . For example, the following code gets the character at index 9 in a string: String anotherPalindrome = "Niagara.
Strings are ordered sequences of character data, 00:15 and the individual characters of a string can be accessed directly using that numerical index. String indexing in Python is zero-based, so the very first character in the string would have an index of 0 , 00:30 and the next would be 1 , and so on.
The charAt() method returns the character at a specified index (position) in a string.
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)
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With