Wednesday, November 08, 2006

C# String Library Inspired by PHP

C# String Library

"...it struck me that there are a number of useful functions in the PHP string library that are missing in C#'s implentation of String. This library is the result of that wee epiphany.

The intent of the article is to introduce you to the PHP inspired String Library for .Net. ...

  • Base64StringEncode: Base64 encodes a string.
  • Base64StringDecode: Decodes a Base64 string.
  • CaseInsenstiveReplace: A case insenstive replace function.
  • ReplaceFirst: Replaces the first occurrence of a string with the replacement value. The Replace is case senstive. [The inclusion of this method and ReplaceLast was suggested by a reader's comment.]
  • ReplaceLast: Replaces the last occurrence of a string with the replacement value. The replace is case senstive.
  • FilterWords: Removes all the words passed in the filter words parameters. The replace is NOT case sensitive.
  • HasWords: Checks the passed string to see if it contains any of the passed words. Not case-sensitive.
  • HtmlSpecialEntitiesEncode: A wrapper around HttpUtility.HtmlEncode.
  • HtmlSpecialEntitiesDecode: A wrapper around HttpUtility.HtmlDecode.
  • MD5String: MD5 encodes the passed string.
  • MD5VerifyString: Verifies a string against the passed MD5 hash.
  • PadLeftHtmlSpaces: Left pads the passed string using the HTML non-breaking space ( ) for the total number of spaces.
  • CaseInsenstiveReplace: Performs a case insenstive replace.
  • PadLeft: Left pads the passed string using the passed pad string for the total number of spaces. (It will not cut-off the pad even if it causes the string to exceed the total width.)
  • PadRightHtmlSpaces: Right pads the passed string using the HTML non-breaking space ( ) for the total number of spaces.
  • PadRight: Right pads the passed string using the passed pad string for the total number of spaces. (It will not cut-off the pad even if it causes the string to exceed the total width.)
  • RemoveNewLines: Removes the new line (\n) and carriage return (\r) symbols.
  • Reverse: Reverses the passed string.
  • SentenceCase: Converts a string to sentence case.
  • SpaceToNbsp: Converts all spaces to HTML non-breaking spaces.
  • StripTags: Removes all HTML tags from the passed string.
  • TitleCase: Converts a string to title case.
  • TrimIntraWords: Removes multiple spaces between words.
  • NewLineToBreak: Converts each new line (\n) and carriage return (\r) symbols to the HTML <br /> tag.
  • WordWrap: Wraps the passed string at the passed total number of characters (if cuttOff is true)or at the next whitespace (if cutOff is false). Uses the environment new linesymbol for the break text. "

There are some methods I can use here...

It's packaged as a single CS file, so if you're already using C# you can just compile it right into your app. Since I dream in VB.Net, I'll probably wrap it into an assembly (or maybe convert it?).

(via .Net Adventures - C# String Library by Chad Finsterwald)

Update #1 3/6/2008:
Fale (Alejandro Fallas) has found, and commented with, the new location for this library, http://www.wtfdeveloper.com/Default5.aspx).

Thanks Fale!

10 comments:

Mader Law Group said...

Do you still have this string library? I checked several places, including the original post, but it seems to no longer be online. Please email me at justinr (@) yah00

Thanks!

Justin

Greg said...

Looking for it now...

Greg said...

Emailed... Let me know if you get it or not...

Anonymous said...

Hi Greg

Can u mail the string functions to obinna_ekeAtHotmailDotCom Please

Greg said...

Emailed...

Anonymous said...

I found the string library in:
http://www.wtfdeveloper.com/Default5.aspx

Hope this helps someone.

Fale.

Greg said...

You rock! Thank you

Sudipta Mukherjee said...

Hi folks! I created a similar API completely written in C# available for download for FREE from codeplex.com the website is
www.codeplex.com/StringDefs.

It supports all the functionalities in this API
Plus
It has Phonetic Match
String Distance Metrices
All kind of SubString Abstractions you can dream of.

Go Check it out today!

Sudipta
www.consulttoday.com

Anonymous said...

Hi can you please Email me the Libray at verma_rain@yahoo.co.in.

Greg said...

The library is available at, http://www.wtfdeveloper.com/Default5.aspx

(Thanks to Alejandro Fallas for finding it... ;)