Skip to content

Instantly share code, notes, and snippets.

@Jalalx
Created April 29, 2015 21:15
Show Gist options
  • Save Jalalx/2920073925454ec80090 to your computer and use it in GitHub Desktop.
Save Jalalx/2920073925454ec80090 to your computer and use it in GitHub Desktop.
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