Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
With with replacing part of a string with another string
How do I right a code to replace the string between <href </href in the
tag below: <hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href Because this part of the tag "red-dot.png" always varies. I am trying to find a function, or a code, that will replace that part of the line everytime I click a button and supply the new value |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
With with replacing part of a string with another string
On Tue, 3 Nov 2009 12:16:01 -0800, Ayo wrote:
How do I right a code to replace the string between <href </href in the tag below: <hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href Because this part of the tag "red-dot.png" always varies. I am trying to find a function, or a code, that will replace that part of the line everytime I click a button and supply the new value Your specifications are inconsistent. First you write: "How do I right a code to replace the string between <href </href" Then you write: "red-dot.png" always varies. I am trying to find a function, or a code, that will replace that part of the line" I'm guessing you only want to replace that last part of the line. But we still have to pick out the correct line. A regular expression approach, similar to the one I recommended in your previous post about "scale", and which you haven't yet clarified with regard to Rick's questions, will work, but more information is required. For example, is this the only <href on the page? If not, how does it differ from others? A general regex pattern, such as "(<href[\s\S]+?/)[^/]+(?=</href)" along with a replacement string like "$1replace_string" could replace the last part of every URL that is on the page. So it would work if there is only one, but if there are multiples, then you need to provide a method of knowing which you want to replace. So a general, regular expression UDF like: ============================ Option Explicit Function RegSub(s As String, sPat As String, sRepl As String) Dim Re As Object Set Re = CreateObject("vbscript.regexp") With Re .Global = True .ignorecase = True .Pattern = sPat .MultiLine = False End With RegSub = Re.Replace(s, sRepl) End Function ============================== with a formula like: =RegSub(A1,"(<href[\s\S]+?/)[^/]+(?=</href)","$1" & A2) and with A2: green-dot.png Would take A1: <hrefhttp://maps.google.com/mapfiles/ms/icons/red-dot.png</href and return: <hrefhttp://maps.google.com/mapfiles/ms/icons/green-dot.png</href And, as written, it would do that for every URL in A1. --ron |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Replacing \r\n #13#10 to <br in a string? | Excel Programming | |||
Search/Match/Find ANY part of string to ANY part of Cell Value | Excel Worksheet Functions | |||
Replacing Chr(10) in a string | Excel Programming | |||
Replacing a value in the string variable | Excel Programming | |||
Replacing a value within a string using a formula | Excel Programming |