Solved

Replace parts of string.

Posted on 2004-10-14
11
213 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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