I want to know if it's possible in Vb to access and modify a character from a string. (Btw I think that vb is really bad with the string).
If it's unclear, I mean like in Pascal string[5] would access the fifth char.
Printable View
I want to know if it's possible in Vb to access and modify a character from a string. (Btw I think that vb is really bad with the string).
If it's unclear, I mean like in Pascal string[5] would access the fifth char.
You can use the mid function to extract a exact character within a string. Or you can use the Instr function to find a specific character within a string. Or you can use the Replace function to replace characters in the string. Look these up at the MSDN library site.
http://msdn.microsoft.com/library/
No, but you could create a work around with Left$() and Right$().
This example will replace the fifth character with a 1.
Code:MyStr = "ABCDEFGHIJKLMNOP"
MyStr = Left$(MyStr, 4) & "1" & Right(MyStr, Len(MyStr) - 5)
Print MyStr
Would this not be better Megatron?
VB Code:
Dim str As String str = "Hello, this is a cool string" Mid$(str, 5, 1) = "1" MsgBox str
Try the Replace() Function. It will find the characters you want and replace them, or any of the other functions work too. (But with a Mid or Left function you need to split it into other strings then concatenate them back together with the new character in the middle.
no you don't, see up one.Quote:
Originally posted by JaredM
But with a Mid or Left function you need to split it into other strings then concatenate them back together with the new character in the middle.
Oh, good example. I didn't see it.