Inserting characters in between a string

This is not a assignment nor homework. It is just a little programming exercise.

Here's the task i am stucked with for a week. So i think it is time to seek help from others.

Create two textbox and a command button.

The first textbox will contain a word of any length. Once clicking on the command button, the second textbox will show the altered required output.

Let's say i key in "HELP" in textbox 1, on clicking the command button, textbox 2 will appear "H*E*L*P".

Thanks in advance.
dream_thiefAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
For x = 1 to Len(SourceTextbox.Text)
    DestTextBox.Text = DestTextBox.Text & Mid(SourceTextbox.text, x, 1) & "*"
Next x
0
ColosseoCommented:
Hi

here his an alterted version of leew suggestion.
It will reset the destination box each time so that the it wont have the results of the last action.
Also it won't add an asterix to the end of the string (it looks like you only want them to appear in between the current characters)


  ' Get the first character in the source box
  DestTextBox = Mid(SourceTextbox, 1, 1)

  ' For every other character in the source box
  For x = 2 To Len(SourceTextbox)
    ' Add an asterix and then the charactter to the destination box
    DestTextBox = DestTextBox & "*" & Mid(SourceTextbox, x, 1)
  Next x

Cheers

Scott
0
dream_thiefAuthor Commented:
Thanks for the fast response.. i check them out.. and let you guys know.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Shiju SasidharanAssoc Project ManagerCommented:
Hi
Try this
'Dont forget to include reference
' Project ->Reference -> Microsoft VBscript Regular Expressions
'-------------------------------------------------------------------------------
Private Sub Command1_Click()
    Dim objReg As New RegExp
    Dim objMatCol As MatchCollection
    With objReg
        .Global = True
        .IgnoreCase = True
        .Pattern = "([\w])"
    End With
    Text2.Text=""
    Set objMatCol = objReg.Execute(Trim(Text1.Text))
    If objMatCol.Count > 0 Then
        Text2.Text = objReg.Replace(Text1.Text, "$1" & "*")
        If Right(Text2.Text, 1) = "*" Then
           Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1)
        End If
    End If
   
End Sub

'---------------------------------
;-)
Shiju
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DaveCommented:
Hi dream_thief,

If you went down a RegExp path then a Replace method is simplest

But for a simple string I'd go with leew's example. The RegEx is useful when the pattern is more complex

Private Sub CommandButton1_Click()
    Dim RegEx, NewString As String
    Set RegEx = CreateObject("vbscript.regexp")
    With RegEx
        .Global = True
        .Pattern = "([a-zA-Z])"
    End With
    NewString = RegEx.Replace(TextBox1.Text, "$1*")
    TextBox2.Text = Left(NewString, Len(NewString) - 1)
End Sub

Cheers

Dave
0
dream_thiefAuthor Commented:
Thanks everyone. I think i should split the points with each of you guys. Since all the answers helped.

Colosseo would have the largest portion since it is the one i was looking for. just minor modifications needed. Thanks.
0
Shiju SasidharanAssoc Project ManagerCommented:
Hi dream_thief

 Thanks for the Points

;-)
Shiju
0
ColosseoCommented:
Glad to have helped

Cheers

Scott
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.