Domanda

I have a connection to Lync sql database. The problem is that saome messages are stored as HTML and some looke like:

{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;}}
{\colortbl ;\red0\green0\blue0;}
{\*\generator Riched20 15.0.4420}{\*\mmathPr\mwrapIndent1440 }\viewkind4\uc1 
\pard\cf1\embo\f0\fs20 this\embo0  \embo is\embo0  \embo from\embo0  \embo 
db\embo0\f1\par
{\*\lyncflags rtf=1}}

It's easy to handle HTML-encoded messages, but how can I get at least text from the other type?
Deoes Lync SDK allows to do this? I didn't find how to do this with Lync SDK.
Even if Lync SDK allows to get message text I don't want to install SDK just for this purpose. Hope that there is a better way. Maybe there are free 3rd party parsers for this?

È stato utile?

Soluzione

The text is in RTF fornmat. You can convert the RTF text to plain text using the RichTextBox inthe System.Windows.Forms namespace.

First you create a richtextbox and provide it with the text.

System.Windows.Forms.RichTextBox richTextBox = new System.Windows.Forms.RichTextBox();
richTextBox.Rtf = rtfText;

You can then read the plain text

string plainText = richTextBox.Text;

When doing this on the text in your example it plainText returns: this is from db.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top