using System;
using System.Text.RegularExpressions;
using System.Text;
namespace Sog
{
public static class StringUtils
{
///
/// 判断字符串是否是合法的email地址
/// 每个公司的邮箱格式不一定一样,去掉算了
///
///
///
public static bool IsValidEmailAddress(string email)
{/*
String strExp = @"^([A-Za-z0-9]{1}[A-Za-z0-9_]*)@([A-Za-z0-9_]+)[.]([A-Za-z0-9_]*)$";
Regex r = new Regex(strExp);
Match m = r.Match(email);
return m.Success;
*/
return true;
}
public static string ToHexString(byte[] bytes)
{
string hexString = string.Empty;
if (bytes != null)
{
StringBuilder strB = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
strB.Append(bytes[i].ToString("X2"));
}
hexString = strB.ToString();
}
return hexString;
}
public static string ToHexString(byte[] bytes, int length)
{
string hexString = string.Empty;
if (bytes != null)
{
StringBuilder strB = new StringBuilder();
for (int i = 0; i < bytes.Length && i < length; i++)
{
strB.Append(bytes[i].ToString("X2"));
}
hexString = strB.ToString();
}
return hexString;
}
public static byte[] HexStringToBytes(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
{
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return returnBytes;
}
}
}