Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding char at position in string

Status
Not open for further replies.

dracuella

Programmer
Mar 10, 2001
4
DK
If I have a string (eg. "im so damn stupid") how do I determine which char is at say, position 11? I've done java, c++ and to some extend delphi as well so when I started VB I assumed all the charAt() and position() functions would be there. However, I cannot find any, so perhaps it's me who's missing out on something?

Sincerely,
drac

_______________________

Live long and prosper..
 
Hi drac,

you have to use mid$() like:



dim str as string
dim strResult as string

str = "im so damn stupid"

strResult = mid$(str,11,1)




strResult will be the 11th char in the string. look vb help for more info on mid.

regards,
nicsin
 
char x = mid(stringname, startposition, length) so to get the character at position eleven use
mid(stringname, 11, 1)

Mark

The key to immortality is to make a big impression in this life!!
 
Dim strChar As String
Dim strText As String

strText = "im so damn stupid"

strChar = Mid$(strText, 11, 1) ' 11 = start position / 1 = length

'To get x amount from left

strChar = Left(strText, 5) ' first five char's

'To get x amount from right

strChar = Right(strext, 3) ' last three char's
 
>I cannot find any

drac, first thing to do is press F2 in the VB IDE and the object browser will come up.

The select from the dropdown combo VBA and review the methods of the VBA string manipulation functions.

At the bottom of the window you will see the syntax needed, and most often a short description of what the method, property or event is for. You can also click on one of these and press F1 for extended help.
 
Thank you all, it works beautifully (obviously :))
And CCLINT, I've been in the object browser a few times but I have to install help for it to aid me ;)

-Dracuella

_______________________

Live long and prosper..
 

>but I have to install help for it to aid me

So, why are you not installing help?
You need to do this.
You do not need to install all of the help files on the CD as a full installation, if space is a matter.
Just have the CD ready when called for.
 
This is usefully...




I got a tokenizer sample:
Code:
 re.Pattern = "\w+\,"
    re.IgnoreCase = False                  ' case sensitive search
    re.Global = True                       ' find all the occurrences
    ReDim arr(1 To nCant)
    i = 1
    For Each ma In re.Execute(cCodigo)
        arr(i) = Left(ma.Value, Len(ma.Value) - 1)
        i = i + 1
    Next

cheers,

--
Luis MX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top