Kivela Developers blog, star date 47410.2

4Jul/082

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

Filed under: Tech 2 Comments
25Mar/087

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'
Step 1

Click on the 'Body' link to alter the field:
Step 2

Then choose 'Enhanced Rich Text' to enable the wanted buttons:
Step 3

Et voila :)

Filed under: Tech 7 Comments
20Feb/082

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 !

Before:
before ‘clicking’ checkbox

After:
After the checkbox

Filed under: Tech 2 Comments
11Dec/072

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

Filed under: Tech 2 Comments
9Jul/071

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 !

Filed under: Tech 1 Comment
nike hyperdunkpaul smith bagoakley sunglasses 2011gucci bagspandora charmralph lauren sale puma speed catchanel handbags sale puma shoesdesigner handbags