Stripping RTF from a text field

  • Hello Everyone,
         I'm hoping to get a little help so here's my situation:

         I have a table that has a text field (varchar(MAX) to be exact). We will name this field "Text". The text in this field has RTF tags in it. 

         Here are a few RTF tags that were listed:

    {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}
    {\colortbl ;\red128\green128\blue0;\red0\green0\blue0;}
    \viewkind4\uc1\pard{\pntext\f1\'B7\tab} - Yes there is no opening bracket for this, I double checked it

    What I would like to do is run a procedure that would strip the RTF tags and just leave the plain text.  Now I know this can't be an easy procedure so any and all help will be greatly appreciated!

    Thanks!

  • I've done this with a Common Language Runtime (CLR)that was unsafe(due to windows.forms) so i could create an RTF object and get the MyObject.Text from it.
    if you google, you will see a lot of CLR examples.
    there's a few old posts here on SSC that have examples of stripping RTF characters, but it's not perfect results, especially compared to the CLR results.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Stripping out tags of that nature is fraught with all kinds of potential "gotchas".   Especially when at least one of them is in the category of "improperly formed".   However, if you can identify all the tags, you can filter them all out, as long as there's a way to distinguish regular text from these tag values.   And that's about as far as I can go with what you've provided so far.   Much more detail needed to get any closer to a solution.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • I guess what I need to do is go through the text and and REPLACE clauses in my procedure to remove the tags and finish it off with trims.  RIght now I'm creating a temp table and throwing the values there, so before inserting it into an actual table, I can process it there.

    thanks for the help!!! 🙂

Viewing 4 posts - 1 through 3 (of 3 total)

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