?
Solved

Replace parts of string.

Posted on 2004-10-14
11
Medium Priority
?
218 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Accepted Solution

by:
wguerram earned 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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