How to store Colored Text in a Database Field Using Text instead of RTF ?

I've a richtextbox control in a Windows forms application, and there's a VarChar field in a database table that is connected to it. I only need to color some of the words in this richtextbox. When I save the richtextbox control's Text property to the database, it saves only the text without colors so I have to save the richtextbox control's Rtf property. Unfortunately this causes a probelm because when I query my table from the SQL Server Management Studio, or any other way, it shows me the RTF special characters, like this example:

{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang3073{\fonttbl{\f0\fnil\fcharset178 Microsoft Sans Serif;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}

Of course, that prevents me from properly searching or sorting the data because of the RTF characters.

Questions :

1- Is it best to save important data in RTF format in database, and if it's safe and reliable, how can I manipulate the Text in the database without importing it into a richtextbox?

2- The only option I need from the RTF is colored text with background color. I only need to color my text with 4 colors (red, green, yellow and blue) and to make the background color for some text black. Is there a way to work with the richtextbox control's Text property and save the color property with it? For example, writing a color code before every word that needs to be colored, like "/R/ for red text /R/" and "/G/ for green text /G/"?

Am I thinking about this right or am I stuck with the RTF?


Things like color is a presentation role, so it shouldn't be in ddbb for regular text. In this case, it's more like a document with formatting, and RTF seems appropriate.

If you need to make queries over this text, you can store the text in a another column as plain text, without formatting.

Depend on your design, Oscar's solution is good, you can keep the original color format and queries the plain text. But it looks like it'll increase the storage size. You need to use two column to store the same data only different in formatting.

And your own solution, put a color code in the text is good, but you'll need to do more processing before display (change from color code format to RTF) and before save (change from RTF to color code format).

You also need to consider what if you need more formatting in future? Example: more color, or even need to store style like bold, italic. If this happen, you do not need to change your code if using Oscar's method, but you'll need to change your code if you use your color code method.

Need Your Help

Swift callback functions

swift macos the-amazing-audio-engine

I'm trying to use The Amazing Audio Engine to record some audio using Swift on OS X. To do this, I need to implement a callback function that will receive the audio and do something with it. The

iOS / Xcode : Outpot posix_spawn() result to debug console

ios objective-c iphone xcode

Is there any way to output the result of posix_spawn() to the Xcode debug console with iOS ?