Results 1 to 7 of 7

Thread: How to access and modify a single character

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    10

    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.

  2. #2
    hellswraith
    Guest
    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/

  3. #3
    Megatron
    Guest
    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

  4. #4
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Would this not be better Megatron?
    VB Code:
    1. Dim str As String
    2.  
    3. str = "Hello, this is a cool string"
    4.  
    5. Mid$(str, 5, 1) = "1"
    6.  
    7. MsgBox str

  5. #5
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    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.

  6. #6
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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.

  7. #7
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    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
  •  



Click Here to Expand Forum to Full Width