Results 1 to 3 of 3

Thread: Please help easy problem i think :(

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    israel
    Posts
    1

    Please help easy problem i think :(

    Hi, i'm kinda new to vb and i need to develope a part of a project and i'm stuck.

    I have a textbox and i want to replace the third letter of the word to "X" that will be written in the textbox for example:

    "working all day"
    "woXing all day" i changed the letter r to X

    How can i specify the position of the letter in the texbox.

    PLease help
    Thank you.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,313

    Re: Please help easy problem i think :(

    vb Code:
    1. dim str as string = textbox1.text
    2. dim charPosition as integer = 3
    3. dim newChar as string = "X"
    4. str = str.substring(0, charPosition -1) & newChar & str.substring(charPosition)
    5. msgbox(str)

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Please help easy problem i think :(

    You can also do it with remove and insert.

    Code:
            Dim myString As String = "working all day"
            myString = myString.Remove(2, 1).Insert(2, "X")
            MessageBox.Show(myString)
    Note that 2 is the index, since the first character in the string is at position 0. That makes the 3rd character in the string position 2.

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