Solved

Replace parts of string.

Posted on 2004-10-14
11
212 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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