Find Replace In String

  • Hi all,

    I have a string which below i mentioned, In that I need to replace '&' symbol with ' ' .

    I can Use Replace function, but in that string may have multiples of <IMG> tags, or nothing..

    I am sending the sample string please give me suggestions to do that in SQL

    Sample String:-

    '<p class="MsoNormal" style="text-align: center;"><span style="FONT-SIZE: 32px">

    <img src="..\..\images\sample1&.jpg" alt="" />

    <img src="..\..\images\change.jpg" alt="" /><strong></strong>'

    Thanks in advance...--)

  • What's the problem exactly? REPLACE() will replace any number of occurrences in a string.

  • Laurie beat me to it. I was going to suggest this:

    REPLACE(strcol, '&.', '.')

    This will only replace the & if it appears prior to the period.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • I wondered if SQLSpider meant any '&' that was within a <img> tag.

    I think the question could do with a little work to clarify it.

  • dwain.c (7/27/2012)


    Laurie beat me to it. I was going to suggest this:

    REPLACE(strcol, '&.', '.')

    This will only replace the & if it appears prior to the period.

    Thanks for your reply it worked

  • BrainDonor (7/27/2012)


    I wondered if SQLSpider meant any '&' that was within a <img> tag.

    I think the question could do with a little work to clarify it.

    what your trying to say.... if you can please explain it ...

  • SqlSpider... (7/27/2012)


    Hi all,

    I can Use Replace function, but in that string may have multiples of <IMG> tags, or nothing..

    Sample String:-

    '<p class="MsoNormal" style="text-align: center;"><span style="FONT-SIZE: 32px">

    <img src="..\..\images\sample1&.jpg" alt="" />

    <img src="..\..\images\change.jpg" alt="" /><strong></strong>'

    Nothing exciting, as dwain appears to have answered to your satisfaction. I thought that your question implied there may be several different tags (not just <img>) and you were only interested replacing '&' where it appeared within <img> tags and no others.

    I was probably looking for a complexity that didn't exist - the story of my life.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply