Skip to content Skip to sidebar Skip to footer

Remove Everything After String

I have a table with a field that contains descriptions for items sold on my site. In our infinite wisdom, when we first started the site, we pasted code for a Facebook Like button

Solution 1:

SELECT 
trim( -- trim removes spaces before and after given string
    left(
        'some text < iframe', 
        locate('< iframe', 'some text < iframe') - 1
    )
);

For better understanding i did not removed space between < and iframe.

You may also take a look at this thread:

Remove HTML tags from record

but this is discussion about removing tags only, and keeping <tag>text</tag> between tags. Anyway it will for for you, because you have nothing between <iframe> and </iframe>.


Solution 2:

  1. REPLACE('<iframe%','<iframe%',' ') will give you just ' ' - it searches first argument for second argument and replaces it with third.
  2. LEFT(somestring, 0) will give you 0 characters string

Solution 3:

Try this:

select substr(your_raw_string, 0, instr(your_raw_string, '<iframe') -1)
from your_table

Post a Comment for "Remove Everything After String"