Created
May 8, 2013 03:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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