using System;
using System.Linq;
using System.Text;
namespace Admin.Core
{
public static class StringExtensions
{
///
/// 判断字符串是否为Null、空
///
///
///
public static bool IsNull(this string s)
{
return string.IsNullOrWhiteSpace(s);
}
///
/// 判断字符串是否不为Null、空
///
///
///
public static bool NotNull(this string s)
{
return !string.IsNullOrWhiteSpace(s);
}
///
/// 与字符串进行比较,忽略大小写
///
///
///
///
public static bool EqualsIgnoreCase(this string s, string value)
{
return s.Equals(value, StringComparison.OrdinalIgnoreCase);
}
///
/// 首字母转小写
///
///
///
public static string FirstCharToLower(this string s)
{
if (string.IsNullOrEmpty(s))
return s;
string str = s.First().ToString().ToLower() + s.Substring(1);
return str;
}
///
/// 首字母转大写
///
///
///
public static string FirstCharToUpper(this string s)
{
if (string.IsNullOrEmpty(s))
return s;
string str = s.First().ToString().ToUpper() + s.Substring(1);
return str;
}
///
/// 转为Base64,UTF-8格式
///
///
///
public static string ToBase64(this string s)
{
return s.ToBase64(Encoding.UTF8);
}
///
/// 转为Base64
///
///
/// 编码
///
public static string ToBase64(this string s, Encoding encoding)
{
if (s.IsNull())
return string.Empty;
var bytes = encoding.GetBytes(s);
return bytes.ToBase64();
}
}
}