Skip to content

Instantly share code, notes, and snippets.

@Konard
Created May 8, 2013 03:09
Show Gist options
  • Save Konard/5537921 to your computer and use it in GitHub Desktop.
Save Konard/5537921 to your computer and use it in GitHub Desktop.
StringExtensions is a static class (module) containing extension-methods for System.String class.
using System;
using System.Globalization;
namespace Helpers
{
public static class StringExtensions
{
public static bool IsInt16(this string s)
{
Int16 result; return Int16.TryParse(s, out result);
}
public static bool IsInt32(this string s)
{
Int32 result; return Int32.TryParse(s, out result);
}
public static byte[] ToBytes(this string s)
{
byte[] bytes = new byte[s.Length * sizeof(char)];
Buffer.BlockCopy(s.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
public static string ToTitleCase(this string s)
{
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment