Replace

M

MFA

Hi All

Help required in replace string.

a= "I am trying to replace a string from 1 point to another point which is
point 2. But I dont know how ? "
b = "This"

Now from string a I want to replace from 1 to 2 with string b="this"
so the final string will be like c
c= "I am trying to replace a string from this. But I dont know how ? "

Regards
 
D

Dan Brussee

c = replace(a, "1 point to another point which is point 2", b)

I think that gets it.
 
W

William Morris

Which works IF the string "1 point to another point which is point 2" is
predictable. If it's not, you'll have to parse the string, maybe adding
some delimiters like:

a= "I am trying to replace a string from #1 point to another point which is
point 2#. But I dont know how ? "
b = "This"

Loop through the string, when you reach a delimiter start storing the string
and stop when you reach the next delimiter. Replace that stored string with
the desired string.

- Wm
 
R

Ray at

a= "I am trying to replace a string from 1 point to another point which is
point 2. But I dont know how ? "
b = "This"

a = "I am trying to replace a string from 1 point to another point which is
point 2. But I dont know how ? "
b = "this"
f1 = InStr(a, "1 point")
f2 = InStr(a, "point 2")
c = Left(a, f1 - 1) & b & Right(a, Len(a) - f2 - Len("point 2") + 1)

Ray at home
 
C

Chris Hohmann

MFA said:
Hi All

Help required in replace string.

a= "I am trying to replace a string from 1 point to another point which is
point 2. But I dont know how ? "
b = "This"

Now from string a I want to replace from 1 to 2 with string b="this"
so the final string will be like c
c= "I am trying to replace a string from this. But I dont know how ? "

<%
Dim s,re
s = "I am trying to replace a string from 1 point to another point which
is point 2. But I dont know how ?"
Set re = New RegExp
re.Global = True
re.Pattern = "1 point(.*?)point 2"
Response.Write re.Replace(s,"this")
%>

HTH
-Chris Hohmann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top