Advertisement

VB6 & Strings

Started by August 07, 2000 08:38 PM
3 comments, last by Prozak 24 years, 5 months ago
Hi all, man, this may seem unbelievably simple, but, i still cant do it, so here i am... How does one manipulate strings in Visual Basic 6? if I have a = "Alpha", can i change the first caracter, "A" to "K", like, for example, A(1) = "B" ???? I know i cant do it this way, but there should be a way of doing this kind of things... I''m used to the way Turbo Pascal 7 handles strings, so... thx a lot all, Hugo Ferreira
You can''t access one char directly in the string. I think that the only way you can do it is with something like this :

A = "K" & Mid(A, 2)

"Mid" is a function that returns a string with all the caraters from the position 2 (the second parameter) to the end. I know, this is not a universal solution but because strings, in vb, are not arrays like in C, you can''t acces the different position directly.
alexk7
Advertisement
Do this:

sText = "Alpha"
Mid$(sText, 1, 1) = "K"

If you want to process lots of characters in a string individually, I would recommend converting the string to a byte array and then you can do stuff like ByteArray(5) = Asc("F")

Later.
try:
a= "K" & mid("Alpha",2,len("alpha")-1)
Mid(string, start[, length])
hmmm thats not very easy ...let me think...i dont know


quote: Original post by pentium3id

Hi all,

man, this may seem unbelievably simple, but,
i still cant do it, so here i am...
How does one manipulate strings in Visual Basic 6?

if I have a = "Alpha", can i change the first
caracter, "A" to "K", like, for example,
A(1) = "B" ????

I know i cant do it this way, but there should be a way
of doing this kind of things...
I''m used to the way Turbo Pascal 7 handles strings, so...

thx a lot all,

Hugo Ferreira


Yes, good idea, TPH. I forgot the mid statement (that is not the mid function I used in my example) when i wrote my reply. So yes, we can access individual caracters in a string....
alexk7

This topic is closed to new replies.

Advertisement