StringExtension - nekonyastudio/DotNetCommonLibrary GitHub Wiki
字符串方法扩展
- 命名空间:
Nekonya
IsMail
bool IsMail()
判断字符串是否位邮箱地址。
用例:
bool isMail = "[email protected]".IsMail();
string mail = "[email protected]";
mail.IsMail();
Reverse
string Reverse()
反转字符串
用例:
string str1 = "abc123";
string str2 = str1.Reverse(); //str2 is "321cba"
EncodeBase64
string EncodeBase64()
将字符串进行Base64编码
用例:
string str1 = "abc123";
string base64 = str1.EncodeBase64(); //base64 is "YWJjMTIz"
DecodeBase64
string DecodeBase64()
Base64文本解码到字符串
用例:
string base64 = "YWJjMTIz";
string text = str1.DecodeBase64(); //text is "abc123456"
IsNullOrEmpty
string IsNullOrEmpty()
字符串是否为空
用例:
string text = "abc";
if(text.IsNullOrEmpty())
{
//xxxxx
}
IsNullOrWhiteSpace
string IsNullOrWhiteSpace()
字符串是否为空或空格
用例:
string text = "abc";
if(text.IsNullOrWhiteSpace())
{
//xxxxx
}
GetMD5
string GetMD5()
获取字符串的MD5
参数:
参数 | 类型 | 说明 | 默认值 |
---|---|---|---|
lower |
bool |
获取小写md5 | true |
shortMD5 |
bool |
获取16位短md5 | false |
用例:
string text = "abc";
string md5_str = text.GetMD5(true);