extracting chars from strings (Visual Basic)

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

If I have a string variable in Visual Basic, which function do I
use to extract/or read a single character in the string??

For example, given the following string:

myString = "ABCDEFG"

How can I instruct Visual Basic to extract the 4th character from
the string??? (which is letter/char 'D')

(In C++, this is equivalent to myString[4])

Thank you!
 
Hi Robert

Mid(mystring,4,1)

--
Regards
Roger Govier

Robert Crandal said:
If I have a string variable in Visual Basic, which function do I
use to extract/or read a single character in the string??

For example, given the following string:

myString = "ABCDEFG"

How can I instruct Visual Basic to extract the 4th character from
the string??? (which is letter/char 'D')

(In C++, this is equivalent to myString[4])

Thank you!




__________ Information from ESET Smart Security, version of virus
signature database 4536 (20091023) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4536 (20091023) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
the entry is in A1

the formula
=MID(A1,4,1)
will give D

if you want vba

Code:
Sub test()
  Dim x As String
  x = Mid(Range("A1"), 4, 1)
  MsgBox x
  End Sub

Is it too trivial solution? That means I have not understood the problem
 
Back
Top