Solved

Stripping RTF characters from Database Field but preserving the "\par" markings.

Posted on 2012-03-23
7
915 Views
Last Modified: 2012-03-23
Need a way to keep "\par" but remove everything else.  Two samples below..one before stripping out RTF and the other is after.  

How would I either leave "\par" in but remove everything else or find the position of "\par" before removing RTF then put them back (more than one).

Thanks,
SISDalia


Original Field before stipping out RTF

{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman\fprq2 Times New Roman;}{\f3\froman Times New Roman;}{\f4\froman Times New Roman;}{\f5\fswiss MS Sans Serif;}}
{\colortbl\red0\green0\blue0;}
\deflang1033\pard\plain\f2\fs24 I am pleased to offer this Medical Student Performance Evaluation for Habibollah S. Alamdari as a candidate for your post-graduate training program.  Habibollah was born and raised in California, to a father who was a mechanic and a mother who was a substitute teacher.  His parents divorced at a young age and he was raised by his mother with limited finances and in a difficult neighborhood.  When his mother remarried he became the eldest of eight siblings, and he learned the necessity of hard work, devotion, and a positive outlook on life.
\par
\par Habibollah spent his formative years in Palmdale, California, where he excelled, moving to the top of his class and graduating as Salutatorian.  As a youth he developed an eye for both the arts and the sciences, leading him to excel in honors courses in Fine Arts and Biology.  He developed and painted murals for his school, was a student leader for the California Scholarship Federation, and excelled in both Cross Country and Wrestling for his high school.
\par
\par Habibollah attended California State University Northridge where he majored in Graphic Design and graduated \plain\f2\fs24\i magna cum laude\plain\f2\fs24 .  He was the president for the Community Medicine group, an active member in the CSUN Peer Helpline, and he spearheaded a program to create a mural at a local elementary school.  He was awarded several scholarships and assisted in research on neural crest cell migration.
\par
\par While in medical school, Habibollah has continued to distinguish himself as both an artist, a researcher, and dedicated member of his community.  He developed a short film that won him an Audience Award at a comedy festival in Los Angeles.  Habibollah continued to explore his interest in research and his work studying drug reactions in patients has led to a first-author publication in a peer reviewed journal and a 2nd place prize at the regional American College of Physicians conference.  He also volunteered his time at the UCLA student run homeless clinic and at the Venice Family Clinic to work with the underserved populations of Los Angeles. He has now completed several research projects with Dermatology faculty at UCLA as well as Wake Forest and the Univeristy of Missouri, the majority of which have been submitted for publication. He has further distinguished himself with a \plain\f2\fs24\b USMLE Step 1 score of 231.
\par \plain\f3\fs24
\par }


Field after stripping out RTF

I am pleased to offer this Medical Student Performance Evaluation for Habibollah S. Alamdari as a candidate for your post-graduate training program. Habibollah was born and raised in California, to a father who was a mechanic and a mother who was a substitute teacher. His parents divorced at a young age and he was raised by his mother with limited finances and in a difficult neighborhood. When his mother remarried he became the eldest of eight siblings, and he learned the necessity of hard work, devotion, and a positive outlook on life. Habibollah spent his formative years in Palmdale, California, where he excelled, moving to the top of his class and graduating as Salutatorian. As a youth he developed an eye for both the arts and the sciences, leading him to excel in honors courses in Fine Arts and Biology. He developed and painted murals for his school, was a student leader for the California Scholarship Federation, and excelled in both Cross Country and Wrestling for his high school. Habibollah attended California State University Northridge where he majored in Graphic Design and graduated magna cum laude. He was the president for the Community Medicine group, an active member in the CSUN Peer Helpline, and he spearheaded a program to create a mural at a local elementary school. He was awarded several scholarships and assisted in research on neural crest cell migration. While in medical school, Habibollah has continued to distinguish himself as both an artist, a researcher, and dedicated member of his community. He developed a short film that won him an Audience Award at a comedy festival in Los Angeles. Habibollah continued to explore his interest in research and his work studying drug reactions in patients has led to a first-author publication in a peer reviewed journal and a 2nd place prize at the regional American College of Physicians conference. He also volunteered his time at the UCLA student run homeless clinic and at the Venice Family Clinic to work with the underserved populations of Los Angeles. He has now completed several research projects with Dermatology faculty at UCLA as well as Wake Forest and the Univeristy of Missouri, the majority of which have been submitted for publication. He has further distinguished himself with a USMLE Step 1 score of 231.
0
Comment
Question by:SISDalia
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37758093
What do you need for the \par elements to be (carriage return, line feed)?

I would suggest transforming the text, and replace the \par with something that doesn't
get recognized as an RTF element, like a carriage return/line feed.

Or, replacing \par with character 127, and then changing it back to \par, after stripping out the other RTF tags.
0
 

Author Comment

by:SISDalia
ID: 37758446
very smart idea. Let me try that! Thanks.
0
 

Author Comment

by:SISDalia
ID: 37758515
So here is what I tried but it isn't working? What am I missing?
Does <p> also get stripped out?

Function StripOutRichText(ByVal strRTF As String)

 
    If strRTF.StartsWith("{\rtf") Then 'Or strRTF.EndsWith "}" Then

      Dim worker As New RichTextBox()
      strRTF.Replace("\par", "<p>")
      worker.Rtf = strRTF
      Return worker.Text
   End If
   strRTF.Replace("<p>", "\par")
   
   Return strRTF

End Function
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 37758557
I would try to replace it with a unique sequence, like "{{Paragraph}}", and then change it back.
0
 

Author Comment

by:SISDalia
ID: 37759064
Now the \par \par is showing up between the text and not actually formatting it.

I'm using a text area to display the field.  is \par the right thing to use for a new line with a text area?

 <textarea id="txtUniqueChar" runat="server" class="editor" rows="25" cols="110" data-prop="UniqueCharacter">&nbsp;</textarea>
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 75 total points
ID: 37759073
For HTML that would be a <br> element.  For Windows Forms, that would be carriage return/line feed.
0
 

Author Comment

by:SISDalia
ID: 37759293
Thanks..that worked.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now