Created
April 29, 2015 21:15
-
-
Save Jalalx/2920073925454ec80090 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace System | |
{ | |
public static class StringExtensions | |
{ | |
public static string RemoveBrackets(this string text) | |
{ | |
return text.Replace("[", "").Replace("]", ""); | |
} | |
public static bool HasBrackets(this string text) | |
{ | |
return text.Contains('[') && text.Contains(']'); | |
} | |
public static string PutInBrackets(this string text) | |
{ | |
if (!HasBrackets(text)) | |
return String.Format("[{0}]", text); | |
return text; | |
} | |
public static string MakeUniqueByDate(this string text) | |
{ | |
var posfix = DateTime.Now.ToString("YYYYMMddHHmmsstt"); | |
return text + posfix; | |
} | |
public static string ToHexString(this byte[] data) | |
{ | |
StringBuilder hexBuilder = new StringBuilder(data.Length * 2); | |
foreach (byte b in data) | |
hexBuilder.AppendFormat("{0:x2}", b); | |
return hexBuilder.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment