ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help replace string within another string (https://www.excelbanter.com/excel-programming/435711-help-replace-string-within-another-string.html)

Ayo

Help replace string within another string
 
I want to replace <scale0.5</scale and <scale0.7</scale in the string of
text belong. This string is in a cell. i only need to change the 0.5 and the
0.7. The point is I don't know what the value between <scale </scale, will
be. I just want to change them.
But there are two <scale </scale in the cell. I need to be able to
differentiate between the first one and the second one. I need to figure out
a way such that when I get the 2 values, i.e, 1.0 and 1.2, that I am going to
replace the old values with, I want to select the cell that contain the
string below and replace in the first <scale0.5</scale with
<scale1.0</scale and the second <scale0.7</scale with <scale1.2</scale
I don't know if it is possible to use something like:
Replace("<scale*.*</scale", "*.*", replace[, start[, count[, compare]]])










"<Style id=""normal_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.5</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.5"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.5</scale
</LabelStyle
</Style
<Style id=""highlight_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.7</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.7"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.7</scale
</LabelStyle
</Style
<StyleMap id=""Actual_StyleMap""
<Pair
<keynormal</key
<styleUrl#normal_MS_Actaul</styleUrl
</Pair
<Pair
<keyhighlight</key
<styleUrl#highlight_MS_Actaul</styleUrl
</Pair
</StyleMap"


Rick Rothstein

Help replace string within another string
 
You are going to have to clarify something for us. You say there are two
<scale...</scale combinations in the text, but I count four of them....
two with 0.5 between them and two with 0.7 between them. Please explain.

--
Rick (MVP - Excel)


"Ayo" wrote in message
...
I want to replace <scale0.5</scale and <scale0.7</scale in the string
of
text belong. This string is in a cell. i only need to change the 0.5 and
the
0.7. The point is I don't know what the value between <scale </scale,
will
be. I just want to change them.
But there are two <scale </scale in the cell. I need to be able to
differentiate between the first one and the second one. I need to figure
out
a way such that when I get the 2 values, i.e, 1.0 and 1.2, that I am going
to
replace the old values with, I want to select the cell that contain the
string below and replace in the first <scale0.5</scale with
<scale1.0</scale and the second <scale0.7</scale with
<scale1.2</scale
I don't know if it is possible to use something like:
Replace("<scale*.*</scale", "*.*", replace[, start[, count[, compare]]])










"<Style id=""normal_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.5</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.5"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.5</scale
</LabelStyle
</Style
<Style id=""highlight_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.7</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.7"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.7</scale
</LabelStyle
</Style
<StyleMap id=""Actual_StyleMap""
<Pair
<keynormal</key
<styleUrl#normal_MS_Actaul</styleUrl
</Pair
<Pair
<keyhighlight</key
<styleUrl#highlight_MS_Actaul</styleUrl
</Pair
</StyleMap"



Ron Rosenfeld

Help replace string within another string
 
On Mon, 2 Nov 2009 17:42:02 -0800, Ayo wrote:

I want to replace <scale0.5</scale and <scale0.7</scale in the string of
text belong. This string is in a cell. i only need to change the 0.5 and the
0.7. The point is I don't know what the value between <scale </scale, will
be. I just want to change them.
But there are two <scale </scale in the cell. I need to be able to
differentiate between the first one and the second one. I need to figure out
a way such that when I get the 2 values, i.e, 1.0 and 1.2, that I am going to
replace the old values with, I want to select the cell that contain the
string below and replace in the first <scale0.5</scale with
<scale1.0</scale and the second <scale0.7</scale with <scale1.2</scale
I don't know if it is possible to use something like:
Replace("<scale*.*</scale", "*.*", replace[, start[, count[, compare]]])










"<Style id=""normal_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.5</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.5"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.5</scale
</LabelStyle
</Style
<Style id=""highlight_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.7</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.7"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.7</scale
</LabelStyle
</Style
<StyleMap id=""Actual_StyleMap""
<Pair
<keynormal</key
<styleUrl#normal_MS_Actaul</styleUrl
</Pair
<Pair
<keyhighlight</key
<styleUrl#highlight_MS_Actaul</styleUrl
</Pair
</StyleMap"


There are several ways to do this using Regular Expressions. The regular
expression in the UDF below does what you describe. But, as written, it's not
very flexible. Also, it does no error checking. But it will work for the
first two "<scale's"

========================================
Option Explicit
Function ReplScale(s As String, Repl1 As String, Repl2 As String) As String
Dim re As Object
Dim sRepl As String
Const sPat As String = _
"^([\s\S]*?<scale)[^<]*(</scale[\s\S]*?<scale)[^<]*([\s\S]*$)"

sRepl = "$1" & Repl1 & "$2" & Repl2 & "$3"

Set re = CreateObject("vbscript.regexp")
With re
.Global = True
.ignorecase = True
.Pattern = sPat
End With

ReplScale = re.Replace(s, sRepl)
End Function
================================================== ====
--ron

Ayo

Help replace string within another string
 
The first combination are the 0.5s inside "<Style id=""normal_MS_Actaul""
and the other arev 0.7s inside the "<Style id=""normal_MS_Projected"" tag.

"Rick Rothstein" wrote:

You are going to have to clarify something for us. You say there are two
<scale...</scale combinations in the text, but I count four of them....
two with 0.5 between them and two with 0.7 between them. Please explain.

--
Rick (MVP - Excel)


"Ayo" wrote in message
...
I want to replace <scale0.5</scale and <scale0.7</scale in the string
of
text belong. This string is in a cell. i only need to change the 0.5 and
the
0.7. The point is I don't know what the value between <scale </scale,
will
be. I just want to change them.
But there are two <scale </scale in the cell. I need to be able to
differentiate between the first one and the second one. I need to figure
out
a way such that when I get the 2 values, i.e, 1.0 and 1.2, that I am going
to
replace the old values with, I want to select the cell that contain the
string below and replace in the first <scale0.5</scale with
<scale1.0</scale and the second <scale0.7</scale with
<scale1.2</scale
I don't know if it is possible to use something like:
Replace("<scale*.*</scale", "*.*", replace[, start[, count[, compare]]])










"<Style id=""normal_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.5</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.5"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.5</scale
</LabelStyle
</Style
<Style id=""highlight_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.7</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.7"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.7</scale
</LabelStyle
</Style
<StyleMap id=""Actual_StyleMap""
<Pair
<keynormal</key
<styleUrl#normal_MS_Actaul</styleUrl
</Pair
<Pair
<keyhighlight</key
<styleUrl#highlight_MS_Actaul</styleUrl
</Pair
</StyleMap"


.


Rick Rothstein

Help replace string within another string
 
But what did you want replaced? You gave us two "replacement" numbers and
there appear to be four <scale values to replace. How is that supposed to
work? Did you only want the first two of the four <scale values replaced,
or are we supposed to replace the first <scale value and all other <scale
values with that number in it with the first "replacement" number and
similarly for the second <scale value?

--
Rick (MVP - Excel)


"Ayo" wrote in message
...
The first combination are the 0.5s inside "<Style id=""normal_MS_Actaul""
and the other arev 0.7s inside the "<Style id=""normal_MS_Projected""
tag.

"Rick Rothstein" wrote:

You are going to have to clarify something for us. You say there are two
<scale...</scale combinations in the text, but I count four of them....
two with 0.5 between them and two with 0.7 between them. Please explain.

--
Rick (MVP - Excel)


"Ayo" wrote in message
...
I want to replace <scale0.5</scale and <scale0.7</scale in the
string
of
text belong. This string is in a cell. i only need to change the 0.5
and
the
0.7. The point is I don't know what the value between <scale </scale,
will
be. I just want to change them.
But there are two <scale </scale in the cell. I need to be able to
differentiate between the first one and the second one. I need to
figure
out
a way such that when I get the 2 values, i.e, 1.0 and 1.2, that I am
going
to
replace the old values with, I want to select the cell that contain the
string below and replace in the first <scale0.5</scale with
<scale1.0</scale and the second <scale0.7</scale with
<scale1.2</scale
I don't know if it is possible to use something like:
Replace("<scale*.*</scale", "*.*", replace[, start[, count[,
compare]]])










"<Style id=""normal_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.5</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.5"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.5</scale
</LabelStyle
</Style
<Style id=""highlight_MS_Actaul""
<IconStyle
<colorff7f00ff</color
<scale0.7</scale
<Icon

<hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href
</Icon
<hotspot x=""0.7"" y=""0""
xunits=""fraction"" yunits=""fraction""/
</IconStyle
<LabelStyle
<scale0.7</scale
</LabelStyle
</Style
<StyleMap id=""Actual_StyleMap""
<Pair
<keynormal</key
<styleUrl#normal_MS_Actaul</styleUrl
</Pair
<Pair
<keyhighlight</key

<styleUrl#highlight_MS_Actaul</styleUrl
</Pair
</StyleMap"


.




All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com