Solved

Replace parts of string.

Posted on 2004-10-14
11
211 Views
Last Modified: 2010-04-23
I have a string like this

strSearchData = "This is $!$text$!$. Here is some more $!$text$!$ for you to read."

Next I have an array

myArray(0) = "<B>"
myArray(1) = "</B">"
myArray(2) = "<I>"
myArray(3) = "</I>"


What I need to do is replace the first instance of $!$ in strSearchData with the value of myArrya(0)
Then I want to replace the second instance of $!$ with the value of myArray(1)
Replace the third instance of $1$ with the value of myArray(2)
and so on.
How do I do this.
0
Comment
Question by:CUTTHEMUSIC
  • 4
  • 4
  • 3
11 Comments
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12307840
HI,
you want to do this just for this phrase  or you need a generic code ?
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 12307926
I need code that searches a string for $!$ and replaces it with the corresponding array value. The $!$ is not always around the word "text" it could be around any word.
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12307982
you mean,
This is $!$text$!$. Here is some more $!$text$!$ for you to read
must result:
This is <b>text</b>. Here is some more <i>text</i> for you to read ??

0
 
LVL 8

Accepted Solution

by:
wguerram earned 125 total points
ID: 12307990
Try this:

Dim strSearchData = "This is $!$text$!$. Here is some more $!$text$!$ for you to read."        
        Dim myArray(3) As String

        myArray(0) = "<B>"
        myArray(1) = "</B>"
        myArray(2) = "<I>"
        myArray(3) = "</I>"

        Dim i As Integer
        For i = 0 To myArray.Length - 1
            strSearchData = Replace(strSearchData, "$!$", myArray(i), , 1)
        Next

        MsgBox(strSearchData)
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 12308040
Gerente
That is the correct result.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 10

Expert Comment

by:Hans Langer
ID: 12308084
Ok, Then, you can try  the code of wguerram.
GL
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 12308119
mguerram
Your code ouputs this

This is <b>text</b>$!$. Here is some more $!$<b>text</b>$!$ for you to read
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12308172
Its work fine for me.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12308180
It's weird i just copy and paste it form my program and the output is:

This is <b>text</b>. Here is some more <b>text</b> for you to read

Copy your code exactly as you have it your program to take a look at it.
0
 
LVL 2

Author Comment

by:CUTTHEMUSIC
ID: 12308213
Sorry, I had a typo when I integrated it with my code.
Thanks for the help.
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12308263
You're welcome
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now