Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing \r\n #13#10 to <br in a string? jodleren Excel Programming 1 October 9th 08 09:26 AM
Search/Match/Find ANY part of string to ANY part of Cell Value TWhizTom Excel Worksheet Functions 0 July 21st 08 08:16 PM
Replacing Chr(10) in a string Barb Reinhardt Excel Programming 2 November 7th 06 08:48 PM
Replacing a value in the string variable Maxi[_2_] Excel Programming 7 August 12th 06 05:26 PM
Replacing a value within a string using a formula solo_razor[_17_] Excel Programming 2 October 30th 03 09:46 AM


All times are GMT +1. The time now is 07:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"