Solved

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

Posted on 2012-03-23
7
918 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach 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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

920 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

16 Experts available now in Live!

Get 1:1 Help Now