Rtf stripper
Have you ever had the need to parse an rtf file to normal text ?
One option (and the easiest one) is just using the RichTextControl, setting its RTF property and getting its text property.
If however your not in a UI project it just smells to add a controls reference to do just a simple parsing, or to be more precise a simple stripping.
Since one of my collegues needed such functionality we ended up converting an old c function to the following.
public static String Strip(String rtf)
{
String strCopy = "";
bool slash = false; //indicates if backslash followed by the space
bool figure_opened = false; //indicates if opening figure brace followed by the space
bool figure_closed = false; //indicates if closing brace followed by the space
bool first_space = false; //the else spaces are in plain text and must be included to the result
int length = rtf.Length;
if (length < 4) return "";
int start = 0;
int k = 0;
start = rtf.IndexOf(@"\pard");
if (start < 1) return "";
char ch;
for (int j = start; j < length; j++)
{
ch = rtf[j];
if (ch == '\\')//we are looking at the backslash
{
first_space = true;
slash = true;
}
if (ch == '{')
{
first_space = true;
figure_opened = true;
}
if (ch == '}')
{
first_space = true;
figure_closed = true;
}
if (ch == ' ' && rtf.IndexOf(@"\datafield", j - 10) + 10 != j)
{
slash = false;
figure_opened = false;
figure_closed = false;
}
if (ch == '\\' && rtf[j + 1] == '{') //if the text contains symbol '{'
{
slash = false;
figure_opened = false;
figure_closed = false;
first_space = false;
strCopy += '{';
j++; k++;
continue;
}
if (ch == '\\' && rtf[j + 1] == '}') //if the text contains symbol '}'
{
slash = false;
figure_opened = false;
figure_closed = false;
first_space = false;
strCopy += '}';
j++; k++;
continue;
}
if (ch == '\\' && rtf[j + 1] == '\\')//if the text contains symbol '\'
{
slash = false;
figure_opened = false;
figure_closed = false;
first_space = false;
strCopy += '\\';
j++;
continue;
}
if (rtf.IndexOf("\\par ", j) == j && rtf.IndexOf("\\pard", j) != j)//if there is next line of text
{
slash = false;
figure_opened = false;
figure_closed = false;
first_space = false;
strCopy += '\n';
j += 4;
continue;
}
if (rtf.IndexOf("HYPERLINK", j) == j)
{
int i = rtf.IndexOf('"', j) - j + 1;
while (rtf[j + i] != '"')
{
i++;
}
j = j + i + 1;
continue;
}
if (slash == false && figure_opened == false && figure_closed == false && ch != '\n' /*&& ch!=13*/ && rtf.IndexOf("HYPERLINK", j + 1) != j + 1)
{
if (!first_space)
{
strCopy += ch;
}
else
{
first_space = false;
}
}
}
return strCopy;
}
Hope it can save somebody half an hour
Cheers Stefan
Insert hyperlink button on Moss announcement lists
A while back we decided to add an 'insert hyperlink' button to the announcement lists on our team system project portals (sharepoint services 3.0). After looking up many articles claiming we had to change our Schema.xml files, javascript files or even creating custom buttons, I discovered the following solution.
First go to your announcement list and choose 'List Settings'
Click on the 'Body' link to alter the field:
Then choose 'Enhanced Rich Text' to enable the wanted buttons:
Et voila
Enabling double tap as double click in osx
It took me 3 months before even bothering to look it up, and now I found it, I can't imagine not using it, so just a quick share to other macbook / airbook owners.
Even in OSX it is possible to double click by double tapping the trackpad, although it isn't as 'it just works' simple as you would expect.
So how do we do the magic
... Just open system preferences - Keyboard and mouse
Then 'Trackpad' and change the 'Clicking' checkbox to checked state and all of a sudden the checkbox below that one will change from content, just hit apply and voila !
Strong signing a third party assembly in .net
Just a quick tip for all you codeplex/codeproject code downloading junkies
Solution for assigning a strong name to a third party DLL using your visual studio command prompt.
E.g. Lets say the name of the third party DLL is myTest.dll.
Step 1: Dis-assemble the assembly
ildasm myTest.dll /out:myTest.il
Step 2: Re-Assemble using your strong-name key
ilasm myTest.il /res:myTest.res /dll /key:myTest.snk /out:myTestSN.dll
for verification you can use following command,
sn -vf myTestSN.dll
Disabling the startup chime of a MacBook (iMac)
I searched for this thingy quite some time so here is a quick tip.
If the startup sound of your macbook, iMac or any recent mac computer starts to bother you you can turn it down (or mute it) with following tool: Psst.
It doesn't get any easier then this
Just download the dmg file, fire it up, choose the volume of the chime (muting is also possible) and voila !