P3.NET

String Extension Methods

Haven’t posted in a while and don’t have a lot of time today so I’ll just throw up a copy of the string extension methods I’ve been using over the years.  Summary of the provided functions (note that not all of them have been fully tested).

  • Combine – Basically acts like String.Join but handles cases where the delimiters are already part of the string.
  • Is… – Equivalent to Char.Is… but applies to an entire string.
  • Left/Right – Gets the leftmost/rightmost N characters in a string.
  • LeftOf/RightOf – Gets the portion of a string to the left/right of a character or string.
  • Mid – Gets a portion of a string.
  • IndexOfNone/LastIndexOfNone – Finds the index of the first character NOT IN a list of tokens.
  • ReplaceAll – Replaces all occurrences of a token with another token.
  • ToCamel/ToPascal – Camel or Pascal cases a string.
  • ToMultipleWords – Pretty prints a string such as taking SomeValue and converting it to “Some Value”.

Download the Library Code