views:

1049

answers:

1

I'm currently beating my head against a wall trying to figure this out. But long story short, I'd like to convert a string between 2 UTF-8 '\u0002' to bold formating. This is for an IRC client that I'm working on so I've been running into these quite a bit. I've treid regex and found that matching on the rtf as ((\'02) works to catch it, but I'm not sure how to match the last character and change it to \bclear or whatever the rtf formating close is.

I can't exactly paste the text I'm trying to parse because the characters get filtered out of the post. But when looking at the char value its an int of 2.

Here's an attempt to paste the offending text:

[02:34] test test

+1  A: 

You could use either

rtb.Rtf = Regex.Replace(rtb.Rtf, @"\\'02\s*(.*?)\s*\\'02", @"\b $1 \b0");

or

rtb.Rtf = Regex.Replace(rtb.Rtf, @"\\'02\s*(.*?)\s*\\'02", @"\'02 \b $1 \b0 \'02");

depending on whether you want to keep the \u0002s in there.

The \b and \b0 turn the bold on and off in RTF.

Daniel LeCheminant
Thanks so much... that worked!
Justin Drury