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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String manipulations

Status
Not open for further replies.

tytus2005

Programmer
Jul 5, 2005
16
PL
I wonder if there is any way to manipulate strings in VBA just like it can be done in C/C++. I mean - is there any way to do something like accessing single letter with []? For example is there any way to check for example third letter in a word in C/C++ way (word[2])?
 
Use the MID function like this:

Mid(mystring, 3, 1)



Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
I have used the following:

MyString = "some where over the rainbow?"

MyAnswer = InStr(1, MyString, "w")

MyAnswer will equal 6

If I was looking for the letter "q" then MyAnswer will = 0

Hope this helps.
 
If your code is string manipulation intensive it may be faster to convert the strings to a byte array and back. Otherwise, Glenn & lucrahouse's suggestions are the simplest. VBA allows the following direct assignments, with regard to byte arrays:
Code:
Dim abytTemp() as Byte
Dim strInput as String
Dim strOutput as string

   strInput = "Somewhere over the rainbow"
   abytTemp = strInput
   ...
   strOutput = abytTemp


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top