Solved

Replace parts of string.

Posted on 2004-10-14
11
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

705 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