|
-
Oct 31st, 2001, 03:28 PM
#1
Thread Starter
New Member
How to access and modify a single character
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.
-
Oct 31st, 2001, 03:35 PM
#2
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/
-
Oct 31st, 2001, 03:36 PM
#3
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
-
Oct 31st, 2001, 04:09 PM
#4
PowerPoster
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
-
Oct 31st, 2001, 04:14 PM
#5
Hyperactive Member
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.
-
Oct 31st, 2001, 04:17 PM
#6
PowerPoster
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.
no you don't, see up one.
-
Oct 31st, 2001, 04:18 PM
#7
Hyperactive Member
Oh, good example. I didn't see it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|