using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
|
|
namespace DataexchangeServer
|
{
|
/// <summary>
|
/// ×Ö·û´®º¯Êý¸¨ÖúÀà¡£
|
/// </summary>
|
public class StringHelper
|
{
|
/// <summary>
|
/// SQL±í´ïʽ·Ö½â±í´ïʽÖеÄÌØÊâ²ÎÊý£¬°üÀ¨²ÎÊý¡¢¸¸¼Ç¼¡¢¼Ç¼¡¢È«¾Ö±äÁ¿µÈ¡£
|
/// Àý£º½«±í´ïʽ
|
/// Éú²úÊý>90 AND ¹¤ºÅ=para:P0123 OR DMA002=parent:DMA001 OR Ãû³Æ=field:D01 OR AA=@@01
|
/// ÖеÄÌØÊâ²ÎÊý²éÕÒ³öÀ´:para:P0123,parent:DMA001,field:D01,@@01
|
/// </summary>
|
public const string Rggex_SqlExpression = @"\w+[><=]\w*((para|parent|field|@@)([:]*)+\w*)";
|
|
private static Regex RegexBr = new Regex(@"(\r\n)", RegexOptions.IgnoreCase);
|
|
/// <summary>
|
/// µÃµ½ÕýÔò±àÒë²ÎÊýÉèÖÃ
|
/// </summary>
|
/// <returns></returns>
|
public static RegexOptions GetRegexCompiledOptions()
|
{
|
#if NET1
|
return RegexOptions.Compiled;
|
#else
|
return RegexOptions.None;
|
#endif
|
}
|
|
/// <summary>
|
/// ·µ»Ø×Ö·û´®ÕæÊµ³¤¶È, 1¸öºº×Ö³¤¶ÈΪ2¡£
|
/// </summary>
|
/// <returns></returns>
|
public static int GetStringLength(string str)
|
{
|
return Encoding.Default.GetBytes(str).Length;
|
}
|
|
/// <summary>
|
/// ÅжÏ×Ö·û´®µÄ°üº¬¹ØÏµ¡£
|
/// </summary>
|
/// <param name="str">±»°üº¬µÄ×Ö·û´®¡£</param>
|
/// <param name="stringArray">ÒÔÖ¸¶¨·Ö¸ô·ûÃèÊöµÄ×Ö·û´®Êý×é¡£</param>
|
/// <param name="stringSplit">×Ö·û´®Êý×éµÄ·Ö¸ô·û¡£</param>
|
/// <returns>Èç¹û±»°üº¬µÄ×Ö·û´®ÔÚÖ¸¶¨×Ö·û´®Êý×éÖУ¬Ôò·µ»Øtrue,·ñÔò·µ»Øfalse¡£</returns>
|
public static bool IsCompriseString(string str, string stringArray, string stringSplit)
|
{
|
if (stringArray == "" || stringArray == null)
|
{
|
return false;
|
}
|
|
str = str.ToLower();
|
string[] array = SafeSplitString(stringArray.ToLower(), stringSplit);
|
for (int i = 0; i < stringArray.Length; i++)
|
{
|
//string t1 = str;
|
//string t2 = stringArray[i];
|
if (str.IndexOf(array[i]) > -1)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÔÚÖ¸¶¨×Ö·û´®Êý×éÖеÄλÖá£
|
/// </summary>
|
/// <param name="strSearch">´ýËÑË÷µÄ×Ö·û´®¡£</param>
|
/// <param name="stringArray">×Ö·û´®Êý×é¡£</param>
|
/// <param name="caseInsensetive">ÊÇ·ñ²»Çø·Ö´óСд, trueΪ²»Çø·Ö, falseÎªÇø·Ö¡£</param>
|
/// <returns>×Ö·û´®ÔÚÖ¸¶¨×Ö·û´®Êý×éÖеÄλÖÃ, Èç²»´æÔÚÔò·µ»Ø-1¡£</returns>
|
public static int GetIndexInArray(string strSearch, string[] stringArray, bool caseInsensetive)
|
{
|
for (int i = 0; i < stringArray.Length; i++)
|
{
|
if (caseInsensetive)
|
{
|
if (strSearch.ToLower() == stringArray[i].ToLower())
|
{
|
return i;
|
}
|
}
|
else
|
{
|
if (strSearch == stringArray[i])
|
{
|
return i;
|
}
|
}
|
|
}
|
return -1;
|
}
|
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÔÚÖ¸¶¨×Ö·û´®Êý×éÖеÄλÖá£
|
/// </summary>
|
/// <param name="strSearch">×Ö·û´®¡£</param>
|
/// <param name="stringArray">×Ö·û´®Êý×é¡£</param>
|
/// <returns>×Ö·û´®ÔÚÖ¸¶¨×Ö·û´®Êý×éÖеÄλÖÃ, Èç²»´æÔÚÔò·µ»Ø-1¡£</returns>
|
public static int GetIndexInArray(string strSearch, string[] stringArray)
|
{
|
return GetIndexInArray(strSearch, stringArray, true);
|
}
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÊÇ·ñÊôÓÚÖ¸¶¨×Ö·û´®Êý×éÖеÄÒ»¸öÔªËØ¡£
|
/// </summary>
|
/// <param name="strSearch">´ýËÑË÷µÄ×Ö·û´®¡£</param>
|
/// <param name="stringArray">×Ö·û´®Êý×é¡£</param>
|
/// <param name="caseInsensetive">ÊÇ·ñ²»Çø·Ö´óСд, trueΪ²»Çø·Ö, falseÎªÇø·Ö¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsInArray(string strSearch, string[] stringArray, bool caseInsensetive)
|
{
|
return GetIndexInArray(strSearch, stringArray, caseInsensetive) >= 0;
|
}
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÊÇ·ñÊôÓÚÖ¸¶¨×Ö·û´®Êý×éÖеÄÒ»¸öÔªËØ¡£
|
/// </summary>
|
/// <param name="str">´ýËÑË÷µÄ×Ö·û´®¡£</param>
|
/// <param name="stringArray">×Ö·û´®Êý×é¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsInArray(string str, string[] stringArray)
|
{
|
return IsInArray(str, stringArray, false);
|
}
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÊÇ·ñÊôÓÚÖ¸¶¨×Ö·û´®Êý×éÖеÄÒ»¸öÔªËØ¡£
|
/// </summary>
|
/// <param name="str">´ýËÑË÷µÄ×Ö·û´®¡£</param>
|
/// <param name="stringArray">ÄÚ²¿ÒԷֺŷָ´ÊµÄ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsInArray(string str, string stringArray)
|
{
|
return IsInArray(str, SafeSplitString(stringArray, ";"), false);
|
}
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÊÇ·ñÊôÓÚÖ¸¶¨×Ö·û´®Êý×éÖеÄÒ»¸öÔªËØ¡£
|
/// </summary>
|
/// <param name="str">´ýËÑË÷µÄ×Ö·û´®</param>
|
/// <param name="stringArray">ÄÚ²¿ÒÔÖ¸¶¨·Ö¸î·û·Ö¸îµ¥´ÊµÄ×Ö·û´®¡£</param>
|
/// <param name="stringSplit">·Ö¸î×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsInArray(string str, string stringArray, string stringSplit)
|
{
|
return IsInArray(str, SafeSplitString(stringArray, stringSplit), false);
|
}
|
|
/// <summary>
|
/// ÅжÏÖ¸¶¨×Ö·û´®ÊÇ·ñÊôÓÚÖ¸¶¨×Ö·û´®Êý×éÖеÄÒ»¸öÔªËØ¡£
|
/// </summary>
|
/// <param name="str">´ýËÑË÷µÄ×Ö·û´®</param>
|
/// <param name="stringArray">ÄÚ²¿ÒÔÖ¸¶¨·Ö¸î·û·Ö¸îµ¥´ÊµÄ×Ö·û´®¡£</param>
|
/// <param name="stringSplit">·Ö¸î×Ö·û´®¡£</param>
|
/// <param name="caseInsensetive">ÊÇ·ñ²»Çø·Ö´óСд, trueΪ²»Çø·Ö, falseÎªÇø·Ö¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsInArray(string str, string stringArray, string stringSplit, bool caseInsensetive)
|
{
|
return IsInArray(str, SafeSplitString(stringArray, stringSplit), caseInsensetive);
|
}
|
|
|
/// <summary>
|
/// ɾ³ý×Ö·û´®Î²²¿µÄ»Ø³µ/»»ÐÐ/¿Õ¸ñ·ûºÅ¡£
|
/// </summary>
|
/// <param name="str">´ý´¦ÀíµÄ×Ö·û´®¡£</param>
|
/// <returns>´¦ÀíºóµÄ×Ö·û´®¡£</returns>
|
public static string RTrim(string str)
|
{
|
for (int i = str.Length; i >= 0; i--)
|
{
|
if (str[i].Equals(" ") || str[i].Equals("\r") || str[i].Equals("\n"))
|
{
|
str.Remove(i, 1);
|
}
|
}
|
return str;
|
}
|
|
|
/// <summary>
|
/// Çå³ý¸ø¶¨×Ö·û´®ÖеĻسµ¼°»»Ðзû¡£
|
/// </summary>
|
/// <param name="str">ÒªÇå³ýµÄ×Ö·û´®¡£</param>
|
/// <returns>´¦ÀíºóµÄ×Ö·û´®¡£</returns>
|
public static string SafeClearBR(string str)
|
{
|
Match m = null;
|
|
for (m = RegexBr.Match(str); m.Success; m = m.NextMatch())
|
{
|
str = str.Replace(m.Groups[0].ToString(), "");
|
}
|
|
return str;
|
}
|
|
/// <summary>
|
/// ´Ó×Ö·û´®µÄÖ¸¶¨Î»ÖýØÈ¡Ö¸¶¨³¤¶ÈµÄ×Ó×Ö·û´®¡£
|
/// </summary>
|
/// <param name="str">Ô×Ö·û´®¡£</param>
|
/// <param name="startIndex">×Ó×Ö·û´®µÄÆðʼλÖá£</param>
|
/// <param name="length">×Ó×Ö·û´®µÄ³¤¶È¡£</param>
|
/// <returns>×Ó×Ö·û´®¡£</returns>
|
public static string SafeCutString(string str, int startIndex, int length)
|
{
|
if (startIndex >= 0)
|
{
|
if (length < 0)
|
{
|
length = length * -1;
|
if (startIndex - length < 0)
|
{
|
length = startIndex;
|
startIndex = 0;
|
}
|
else
|
{
|
startIndex = startIndex - length;
|
}
|
}
|
|
|
if (startIndex > str.Length)
|
{
|
return "";
|
}
|
|
|
}
|
else
|
{
|
if (length < 0)
|
{
|
return "";
|
}
|
else
|
{
|
if (length + startIndex > 0)
|
{
|
length = length + startIndex;
|
startIndex = 0;
|
}
|
else
|
{
|
return "";
|
}
|
}
|
}
|
|
if (str.Length - startIndex < length)
|
{
|
length = str.Length - startIndex;
|
}
|
|
return str.Substring(startIndex, length);
|
}
|
|
/// <summary>
|
/// ´Ó×Ö·û´®µÄÖ¸¶¨Î»ÖÿªÊ¼½ØÈ¡µ½×Ö·û´®½áβµÄÁË·û´®¡£
|
/// </summary>
|
/// <param name="str">Ô×Ö·û´®¡£</param>
|
/// <param name="startIndex">×Ó×Ö·û´®µÄÆðʼλÖá£</param>
|
/// <returns>×Ó×Ö·û´®¡£</returns>
|
public static string SafeCutString(string str, int startIndex)
|
{
|
return SafeCutString(str, startIndex, str.Length);
|
}
|
|
|
/// <summary>
|
/// intÐÍת»»ÎªstringÐÍ¡£
|
/// </summary>
|
/// <returns>ת»»ºóµÄstringÀàÐͽá¹û¡£</returns>
|
public static string FromInt(int intValue)
|
{
|
//
|
return Convert.ToString(intValue);
|
}
|
|
|
/// <summary>
|
/// ȡָ¶¨³¤¶ÈµÄ×Ö·û´®£¬²¢ÔÚ½ØÈ¡Ê±¿¼ÂÇË«Óï×Ö·û£¬µ±×Ö·û´®Èç¹û²Ù¹ýÖ¸¶¨³¤¶ÈÔò½«³¬³öµÄ²¿·ÖÓÃÖ¸¶¨×Ö·û´®´úÌæ¡£
|
/// </summary>
|
/// <param name="srcString">Òª¼ì²éµÄ×Ö·û´®¡£</param>
|
/// <param name="length">Ö¸¶¨³¤¶È¡£</param>
|
/// <param name="tailString">ÓÃÓÚÌæ»»µÄ×Ö·û´®¡£</param>
|
/// <returns>½ØÈ¡ºóµÄ×Ö·û´®¡£</returns>
|
public static string GetSubString(string srcString, int length, string tailString)
|
{
|
return GetSubString(srcString, 0, length, tailString);
|
}
|
|
|
/// <summary>
|
/// ȡָ¶¨³¤¶ÈµÄ×Ö·û´®£¬²¢ÔÚ½ØÈ¡Ê±¿¼ÂÇË«Óï×Ö·û£¬µ±×Ö·û´®Èç¹û²Ù¹ýÖ¸¶¨³¤¶ÈÔò½«³¬³öµÄ²¿·ÖÓÃÖ¸¶¨×Ö·û´®´úÌæ¡£
|
/// </summary>
|
/// <param name="srcString">Òª¼ì²éµÄ×Ö·û´®¡£</param>
|
/// <param name="startIndex">ÆðʼλÖá£</param>
|
/// <param name="length">Ö¸¶¨³¤¶È¡£</param>
|
/// <param name="tailString">ÓÃÓÚÌæ»»µÄ×Ö·û´®¡£</param>
|
/// <returns>½ØÈ¡ºóµÄ×Ö·û´®¡£</returns>
|
public static string GetSubString(string srcString, int startIndex, int length, string tailString)
|
{
|
|
|
string myResult = srcString;
|
|
//µ±ÊÇÈÕÎÄ»òº«ÎÄʱ(×¢:ÖÐÎĵķ¶Î§:\u4e00 - \u9fa5, ÈÕÎÄÔÚ\u0800 - \u4e00, º«ÎÄΪ\xAC00-\xD7A3)
|
if (System.Text.RegularExpressions.Regex.IsMatch(srcString, "[\u0800-\u4e00]+") ||
|
System.Text.RegularExpressions.Regex.IsMatch(srcString, "[\xAC00-\xD7A3]+"))
|
{
|
//µ±½ØÈ¡µÄÆðʼλÖó¬³ö×ֶδ®³¤¶Èʱ
|
if (startIndex >= srcString.Length)
|
{
|
return "";
|
}
|
else
|
{
|
return srcString.Substring(startIndex,
|
((length + startIndex) > srcString.Length) ? (srcString.Length - startIndex) : length);
|
}
|
}
|
|
|
if (length >= 0)
|
{
|
byte[] bsSrcString = Encoding.Default.GetBytes(srcString);
|
|
//µ±×Ö·û´®³¤¶È´óÓÚÆðʼλÖÃ
|
if (bsSrcString.Length > startIndex)
|
{
|
int endIndex = bsSrcString.Length;
|
|
//µ±Òª½ØÈ¡µÄ³¤¶ÈÔÚ×Ö·û´®µÄÓÐЧ³¤¶È·¶Î§ÄÚ
|
if (bsSrcString.Length > (startIndex + length))
|
{
|
endIndex = length + startIndex;
|
}
|
else
|
{ //µ±²»ÔÚÓÐЧ·¶Î§ÄÚʱ,ֻȡµ½×Ö·û´®µÄ½áβ
|
|
length = bsSrcString.Length - startIndex;
|
tailString = "";
|
}
|
|
|
|
int nRealLength = length;
|
int[] anResultFlag = new int[length];
|
byte[] bsResult = null;
|
|
int nFlag = 0;
|
for (int i = startIndex; i < endIndex; i++)
|
{
|
|
if (bsSrcString[i] > 127)
|
{
|
nFlag++;
|
if (nFlag == 3)
|
{
|
nFlag = 1;
|
}
|
}
|
else
|
{
|
nFlag = 0;
|
}
|
|
anResultFlag[i] = nFlag;
|
}
|
|
if ((bsSrcString[endIndex - 1] > 127) && (anResultFlag[length - 1] == 1))
|
{
|
nRealLength = length + 1;
|
}
|
|
bsResult = new byte[nRealLength];
|
|
Array.Copy(bsSrcString, startIndex, bsResult, 0, nRealLength);
|
|
myResult = Encoding.Default.GetString(bsResult);
|
|
myResult = myResult + tailString;
|
}
|
}
|
|
return myResult;
|
}
|
|
/// <summary>
|
/// ×Ô¶¨ÒåµÄÌæ»»×Ö·û´®º¯Êý¡£
|
/// </summary>
|
/// <param name="sourceString">Ô´×Ö·û´®¡£</param>
|
/// <param name="searchString">´ýÌæ»»µÄ×Ö·û´®</param>
|
/// <param name="replaceString">Ìæ»»ºóµÄ×Ö·û´®</param>
|
/// <param name="caseInsensetive">ÊÇ·ñ²»Çø·Ö´óСд, trueΪ²»Çø·Ö, falseÎªÇø·Ö¡£</param>
|
/// <returns>´¦ÀíºóµÄ×Ö·û´®¡£</returns>
|
public static string SafeReplaceString(string sourceString, string searchString, string replaceString, bool caseInsensetive)
|
{
|
return Regex.Replace(sourceString, Regex.Escape(searchString), replaceString, caseInsensetive ? RegexOptions.IgnoreCase : RegexOptions.None);
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñ·ûºÏemailµØÖ·¸ñʽ¡£
|
/// </summary>
|
/// <param name="strEmail">ÒªÅжϵÄemail×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsValidEmail(string strEmail)
|
{
|
return Regex.IsMatch(strEmail, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñ·ûºÏemailÖ·ÖÐÓòÃû¸ñʽ¡£
|
/// </summary>
|
/// <param name="strEmail">ÒªÅжϵÄemail×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsValidEmailDomain(string strEmail)
|
{
|
return Regex.IsMatch(strEmail, @"^@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñ·ûºÏUrl¸ñʽ¡£
|
/// </summary>
|
/// <param name="strUrl">ÒªÅжϵÄUrl¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsUrl(string strUrl)
|
{
|
return Regex.IsMatch(strUrl, @"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$");
|
}
|
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñΪbase64×Ö·û´®¡£
|
/// </summary>
|
/// <param name="str">ÒªÅжϵÄ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsBase64String(string str)
|
{
|
//A-Z, a-z, 0-9, +, /, =
|
return Regex.IsMatch(str, @"[A-Za-z0-9\+\/\=]");
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñÓÐSqlΣÏÕ×Ö·û¡£
|
/// </summary>
|
/// <param name="str">ÒªÅжÏ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsSafeSqlString(string str)
|
{
|
|
return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']");
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñÓÐΣÏյĿÉÄÜÓÃÓÚÁ´½ÓµÄ×Ö·û´®¡£
|
/// </summary>
|
/// <param name="str">ÒªÅжÏ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsSafeUserInfoString(string str)
|
{
|
return !Regex.IsMatch(str, @"^\s*$|^c:\\con\\con$|[%,\*" + "\"" + @"\s\t\<\>\&]|ÓοÍ|^Guest");
|
}
|
|
/// <summary>
|
/// ÇåÀí×Ö·û´®¡£
|
/// </summary>
|
/// <param name="input">ÊäÈëµÄ×Ö·û´®¡£</param>
|
/// <returns>´¦Àí½á¹û</returns>
|
public static string SafeCleanInput(string input)
|
{
|
return Regex.Replace(input.Trim(), @"[^\w\.@-]", "");
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñΪʱ¼ä×Ö·û´®¡£
|
/// </summary>
|
/// <param name="str">´ýÅжϵÄʱ¼ä×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsTime(string str)
|
{
|
return Regex.IsMatch(str, @"^((([0-1]?[0-9])|(2[0-3])):([0-5]?[0-9])(:[0-5]?[0-9])?)$");
|
}
|
|
|
/*
|
/// <summary>
|
/// ½«×Ö·û´®×ª»»Îª¼òÌåÖÐÎÄ¡£
|
/// (([^"']|^)\[xui:+\w+\.+\w+\.+\w+\])+(\.+\w*)+(\[\d\])?
|
/// [xui:form1.bysv.ss].value[102]=="[xui:form1.bysv.ss]" and [xui:form2.bysv.ss].value==c or [ps:0.1]==d
|
/// </summary>
|
/// <param name="str">´ýת»»µÄ×Ö·û´®¡£</param>
|
/// <returns>ת»»½á¹û¡£</returns>
|
public static string ToSimplifiedChinese(string str)
|
{
|
return Strings.StrConv(str, VbStrConv.SimplifiedChinese, 0);
|
}
|
|
/// <summary>
|
/// ½«×Ö·û´®×ª»»Îª·±ÌåÖÐÎÄ¡£
|
/// </summary>
|
/// <param name="str">´ýת»»µÄ×Ö·û´®¡£</param>
|
/// <returns>ת»»½á¹û¡£</returns>
|
public static string ToTChinese(string str)
|
{
|
return Strings.StrConv(str, VbStrConv.TraditionalChinese, 0);
|
}
|
* */
|
|
/// <summary>
|
/// ·Ö¸î×Ö·û´®¡£
|
/// </summary>
|
/// <param name="srcString">´ý·Ö¸îµÄÔ´×Ö·û´®¡£</param>
|
/// <param name="stringSplit">·Ö¸î·û¡£</param>
|
/// <returns>·Ö¸îºóµÄ×Ö·û´®Êý×é¡£</returns>
|
public static string[] SafeSplitString(string srcString, string stringSplit)
|
{
|
if (srcString.IndexOf(stringSplit) < 0)
|
{
|
string[] tmp = { srcString };
|
return tmp;
|
}
|
return Regex.Split(srcString, Regex.Escape(stringSplit), RegexOptions.IgnoreCase);
|
}
|
|
/// <summary>
|
/// ·Ö¸î×Ö·û´®¡£
|
/// </summary>
|
/// <param name="srcString">´ý·Ö¸îµÄÔ´×Ö·û´®¡£</param>
|
/// <param name="stringSplit">·Ö¸î·û¡£</param>
|
/// <param name="length">·µ»Ø×Ö·û´®Êý¾ÝµÄ³¤¶È£¬Èç¹û²»×ãÔòÒÔ¿Õ×Ö·û´®Ìî³ä¡£</param>
|
/// <returns>·Ö¸îºóµÄ×Ö·û´®Êý×é¡£</returns>
|
public static string[] SafeSplitString(string srcString, string stringSplit, int length)
|
{
|
string[] result = new string[length];
|
|
string[] splited = SafeSplitString(srcString, stringSplit);
|
|
for (int i = 0; i < length; i++)
|
{
|
if (i < splited.Length)
|
result[i] = splited[i];
|
else
|
result[i] = string.Empty;
|
}
|
|
return result;
|
}
|
|
/// <summary>
|
/// ʹÓÃÕýÔò±í´ïʽƥÅä×Ö·û´®£¬ÕÒ³öÿ¸ö·ûºÏÌõ¼þµÄµÚÒ»×éÊý¾Ý¡£
|
/// </summary>
|
/// <param name="regx"></param>
|
/// <param name="source"></param>
|
/// <returns></returns>
|
/// <remarks>ͨ³£ÓÃÓÚÌæ»»±í´ïʽÖеÄÌØÊâ±ê¼Ç¡£</remarks>
|
public static string[] SafeMatchString(string regx, string source)
|
{
|
Regex r = new Regex(regx, RegexOptions.IgnoreCase);
|
Match m = r.Match(source);
|
List<string> s = new List<string>();
|
while (m.Success)
|
{
|
s.Add(m.Groups[1].Value);
|
m = m.NextMatch();
|
}
|
|
|
return s.ToArray();
|
}
|
|
/// <summary>
|
/// ½øÐÐÖ¸¶¨µÄÌæ»»(Ôà×Ö¹ýÂË)¡£
|
/// </summary>
|
/// <param name="str">´ý´¦ÀíµÄ×Ö·û´®¡£</param>
|
/// <param name="bantext">´ý¹ýÂ˵Ä×Ö·û´®£¨Ôà×Ö£©¡£</param>
|
/// <returns>´¦Àí½á¹û¡£</returns>
|
public static string Filter(string str, string bantext)
|
{
|
string text1 = "";
|
string text2 = "";
|
string[] textArray1 = SafeSplitString(bantext, "\r\n");
|
for (int num1 = 0; num1 < textArray1.Length; num1++)
|
{
|
text1 = textArray1[num1].Substring(0, textArray1[num1].IndexOf("="));
|
text2 = textArray1[num1].Substring(textArray1[num1].IndexOf("=") + 1);
|
str = str.Replace(text1, text2);
|
}
|
return str;
|
}
|
|
|
/// <summary>
|
/// ¼ÆËã×Ö½ÚÊý´óС²¢·µ»Ø×îÆ¥Å䵥λµÄÏàÓ¦µÄ×Ö·û´®¡£
|
/// </summary>
|
/// <param name="size">×Ö½Ú´óС¡£</param>
|
/// <returns>×îÆ¥Å䵥λµÄÏàÓ¦µÄ×Ö·û´®¡£</returns>
|
public static string FormatBytesString(int size)
|
{
|
if (size > 1073741824)
|
{
|
return ((double)(size / 1073741824)).ToString("0") + "G";
|
}
|
if (size > 1048576)
|
{
|
return ((double)(size / 1048576)).ToString("0") + "M";
|
}
|
if (size > 1024)
|
{
|
return ((double)(size / 1024)).ToString("0") + "K";
|
}
|
return size.ToString() + "Bytes";
|
}
|
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñ·ûºÏIPµØÖ·¸ñʽ(IPv4)¡£
|
/// </summary>
|
/// <param name="strIp">ÒªÅжϵÄIP×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsIP(string strIp)
|
{
|
return Regex.IsMatch(strIp, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
|
|
}
|
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñÊÇIPµØÖ·¶Î(IPv4)¡£
|
/// </summary>
|
/// <param name="strIp">ÒªÅжϵÄIP×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsIPSect(string strIp)
|
{
|
return Regex.IsMatch(strIp, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){2}((2[0-4]\d|25[0-5]|[01]?\d\d?|\*)\.)(2[0-4]\d|25[0-5]|[01]?\d\d?|\*)$");
|
|
}
|
|
|
/// <summary>
|
/// ½«È«½ÇÊý×Öת»»ÎªÊý×Ö¡£
|
/// </summary>
|
/// <param name="SBCCase">È«½ÇÊý×Ö¡£</param>
|
/// <returns>´¦Àí½á¹û¡£</returns>
|
public static string SBCCaseToNumberic(string SBCCase)
|
{
|
char[] c = SBCCase.ToCharArray();
|
for (int i = 0; i < c.Length; i++)
|
{
|
byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
|
if (b.Length == 2)
|
{
|
if (b[1] == 255)
|
{
|
b[0] = (byte)(b[0] + 32);
|
b[1] = 0;
|
c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
|
}
|
}
|
}
|
return new string(c);
|
}
|
|
|
/// <summary>
|
/// ɾ³ý×îºóÒ»¸ö×Ö·û¡£
|
/// </summary>
|
/// <param name="str">´ý´¦ÀíµÄ×Ö·û´®¡£</param>
|
/// <returns>´¦Àí½á¹û¡£</returns>
|
public static string SafeClearLastChar(string str)
|
{
|
if (str == "")
|
return "";
|
else
|
return str.Substring(0, str.Length - 1);
|
}
|
|
/// <summary>
|
/// ½«×Ö·û´®×ª»»ÎªColor¡£
|
/// </summary>
|
/// <param name="color">ÑÕÉ«×Ö·û´®£¬ÑÕÉ«¿ÉÒÔÊÇÑÕÉ«Ãû£¬Ò²¿ÉÒÔÊÇRGBÖµ»ò±ê×¼ÑÕɫֵ¡£</param>
|
/// <returns>´¦Àí½á¹û¡£</returns>
|
public static Color ToColor(string color)
|
{
|
int red, green, blue = 0;
|
char[] rgb;
|
color = color.TrimStart('#');
|
color = Regex.Replace(color.ToLower(), "[g-zG-Z]", "");
|
switch (color.Length)
|
{
|
case 3:
|
rgb = color.ToCharArray();
|
red = Convert.ToInt32(rgb[0].ToString() + rgb[0].ToString(), 16);
|
green = Convert.ToInt32(rgb[1].ToString() + rgb[1].ToString(), 16);
|
blue = Convert.ToInt32(rgb[2].ToString() + rgb[2].ToString(), 16);
|
return Color.FromArgb(red, green, blue);
|
case 6:
|
rgb = color.ToCharArray();
|
red = Convert.ToInt32(rgb[0].ToString() + rgb[1].ToString(), 16);
|
green = Convert.ToInt32(rgb[2].ToString() + rgb[3].ToString(), 16);
|
blue = Convert.ToInt32(rgb[4].ToString() + rgb[5].ToString(), 16);
|
return Color.FromArgb(red, green, blue);
|
default:
|
return Color.FromName(color);
|
|
}
|
}
|
|
/// <summary>
|
/// ¼ì²â×Ö·û´®ÊÇ·ñÊÇÈÕÆÚ×Ö·û´®¡£
|
/// </summary>
|
/// <param name="str">´ýÅжÏ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsDateString(string str)
|
{
|
return Regex.IsMatch(str, @"(\d{4})-(\d{1,2})-(\d{1,2})");
|
}
|
|
/// <summary>
|
/// ¼ì²âÊÇ·ñΪÕýÕûÊý¡£
|
/// </summary>
|
/// <param name="str">´ýÅжÏ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsPlusInt(string str)
|
{
|
|
return Regex.IsMatch(str, @"^[0-9]*$");
|
}
|
|
/// <summary>
|
/// ¼ì²â¸ø¶¨µÄ×Ö·û´®Êý×é(strNumber)ÖеÄÊý¾ÝÊDz»ÊǶ¼ÎªÊýÖµÐÍ¡£
|
/// </summary>
|
/// <param name="strNumber">ҪȷÈϵÄ×Ö·û´®Êý×é¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsNumericArray(string[] strNumber)
|
{
|
if (strNumber == null)
|
{
|
return false;
|
}
|
if (strNumber.Length < 1)
|
{
|
return false;
|
}
|
foreach (string id in strNumber)
|
{
|
if (!IsNumeric(id))
|
{
|
return false;
|
}
|
}
|
return true;
|
|
}
|
|
/// <summary>
|
/// ¼ì²â×Ö·û´®ÊÇ·ñΪInt32ÀàÐ͵ÄÊý×Ö¡£
|
/// </summary>
|
/// <param name="str">´ýÅжϵÄ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsNumeric(string str)
|
{
|
|
if (str.Length > 0 && str.Length <= 11 && Regex.IsMatch(str, @"^[-]?[0-9]*[.]?[0-9]*$"))
|
{
|
if ((str.Length < 10) || (str.Length == 10 && str[0] == '1') || (str.Length == 11 && str[0] == '-' && str[1] == '1'))
|
{
|
return true;
|
}
|
}
|
|
return false;
|
|
}
|
|
/// <summary>
|
/// ¼ì²â×Ö·û´®ÊÇ·ñΪDoubleÀàÐ͵ÄÊý×Ö¡£
|
/// </summary>
|
/// <param name="str">´ýÅжϵÄ×Ö·û´®¡£</param>
|
/// <returns>ÅжϽá¹û¡£</returns>
|
public static bool IsDouble(string str)
|
{
|
return Regex.IsMatch(str, @"^([0-9])[0-9]*(\.\w*)?$");
|
}
|
|
/// <summary>
|
/// stringÐÍת»»ÎªboolÐÍ¡£
|
/// </summary>
|
/// <param name="str">´ýת»»µÄ×Ö·û´®¡£</param>
|
/// <param name="defaultValue">ȱʡֵ¡£</param>
|
/// <returns>ת»»ºóµÄboolÀàÐͽá¹û¡£</returns>
|
public static bool ToBool(string str, bool defaultValue)
|
{
|
if (str != null)
|
{
|
if (string.Compare(str, "true", true) == 0)
|
{
|
return true;
|
}
|
else if (string.Compare(str, "false", true) == 0)
|
{
|
return false;
|
}
|
}
|
return defaultValue;
|
}
|
|
/// <summary>
|
/// ½«×Ö·û´®×ª»»ÎªInt32ÀàÐÍ¡£
|
/// </summary>
|
/// <param name="str">´ýת»»µÄ×Ö·û´®¡£</param>
|
/// <param name="defaultValue">ȱʡֵ¡£</param>
|
/// <returns>ת»»ºóµÄintÀàÐͽá¹û¡£</returns>
|
public static int ToInt(string str, int defaultValue)
|
{
|
if (str != null)
|
{
|
if (str.Length > 0 && str.Length <= 11 && Regex.IsMatch(str, @"^[-]?[0-9]*$"))
|
{
|
if ((str.Length < 10) || (str.Length == 10 && str[0] == '1') || (str.Length == 11 && str[0] == '-' && str[1] == '1'))
|
{
|
return Convert.ToInt32(str);
|
}
|
}
|
}
|
return defaultValue;
|
}
|
|
/// <summary>
|
/// stringÐÍת»»ÎªfloatÐÍ¡£
|
/// </summary>
|
/// <param name="str">´ýת»»µÄ×Ö·û´®¡£</param>
|
/// <param name="defaultValue">ȱʡֵ¡£</param>
|
/// <returns>ת»»ºóµÄintÀàÐͽá¹û¡£</returns>
|
public static float ToFloat(string str, float defaultValue)
|
{
|
if ((str == null) || (str.Length > 10))
|
{
|
return defaultValue;
|
}
|
|
float intValue = defaultValue;
|
if (str != null)
|
{
|
bool IsFloat = Regex.IsMatch(str.ToString(), @"^([-]|[0-9])[0-9]*(\.\w*)?$");
|
if (IsFloat)
|
{
|
intValue = Convert.ToSingle(str);
|
}
|
}
|
return intValue;
|
}
|
|
|
/// <summary>
|
/// ½«×Ö·û´®×ª»»ÎªInt32ÀàÐÍ
|
/// </summary>
|
/// <param name="str">´ýת»»µÄ×Ö·û´®¡£</param>
|
/// <returns>ת»»ºóµÄInt32ÀàÐͽá¹û¡£</returns>
|
public static int ToInt32(string str)
|
{
|
if (str == null)
|
{
|
return 0;
|
}
|
string strNum = str;
|
if (IsNumeric(strNum))
|
{
|
|
if (strNum.ToString().Length > 9)
|
{
|
if (strNum.StartsWith("-"))
|
{
|
return int.MinValue;
|
}
|
else
|
{
|
return int.MaxValue;
|
}
|
}
|
return Int32.Parse(strNum);
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
/// <summary>
|
/// ½«×Ö·û´®×ª»»ÎªBase64ÀàÐÍ
|
/// </summary>
|
/// <param name="str"></param>
|
/// <returns></returns>
|
public static string ToBase64String(string str)
|
{
|
byte[] data = System.Text.Encoding.Unicode.GetBytes(str);
|
return Convert.ToBase64String(data);
|
}
|
|
/// <summary>
|
/// FromBase64String
|
/// </summary>
|
/// <param name="str"></param>
|
/// <returns></returns>
|
public static string FromBase64String(string str)
|
{
|
byte[] data = Convert.FromBase64String(str);
|
return System.Text.Encoding.Unicode.GetString(data);
|
}
|
|
/// <summary>
|
/// ѹËõ×Ö·û´®
|
/// </summary>
|
/// <param name="str"></param>
|
/// <returns></returns>
|
public static string ToCompressionString(string str)
|
{
|
return str;
|
}
|
|
/// <summary>
|
/// ½âѹ×Ö·û´®
|
/// </summary>
|
/// <param name="str"></param>
|
/// <returns></returns>
|
public static string FromCompressionString(string str)
|
{
|
return str;
|
}
|
|
/// <summary>
|
/// °Ñ×Ö·û´®Êý¾Ýת»¯Îª×Ö·û
|
/// </summary>
|
/// <param name="array"></param>
|
/// <param name="separator"></param>
|
/// <returns></returns>
|
public static string FromStringArray(string[] array, string separator)
|
{
|
string s = string.Empty;
|
foreach (string t in array)
|
s += separator + t;
|
if (s.Length > separator.Length)
|
s = s.Substring(separator.Length);
|
|
return s;
|
}
|
|
/// <summary>
|
/// ½«×Öµäת»»Îª×Ö·û´®±í´ïʽ¡£
|
/// </summary>
|
/// <param name="dic"></param>
|
/// <returns></returns>
|
public static string FromDictionary(Dictionary<string, string> dic)
|
{
|
if (dic.Count == 0)
|
return string.Empty;
|
|
string rstr = string.Empty;
|
foreach (string key in dic.Keys)
|
{
|
rstr += ";" + key + "=" + dic[key];
|
}
|
|
if (rstr.Length > 1)
|
rstr = rstr.Substring(1);
|
return rstr;
|
}
|
|
/// <summary>
|
/// ½«Êý×éת»»Îª×Ö·û´®±í´ïʽ¡£
|
/// </summary>
|
/// <param name="array"></param>
|
/// <param name="dictionary">ÊÇ·ñת»¯Îª×ÖµäÑùʽ</param>
|
/// <returns></returns>
|
public static string FromArray(string[] array,bool dictionary)
|
{
|
if (array.Length == 0)
|
return string.Empty;
|
|
string rstr = string.Empty;
|
foreach (string key in array)
|
{
|
if(dictionary)
|
rstr += ";" + key + "=" + key;
|
else
|
rstr += ";" + key ;
|
}
|
|
if (rstr.Length > 1)
|
rstr = rstr.Substring(1);
|
return rstr;
|
}
|
|
/// <summary>
|
/// ½«×Ö·û´®½âÎöΪ×ֵ䣬ҪÇó×Ö·û´®µÄ¸ñʽΪ:¼ü=Öµ;¼ü=Öµ
|
/// </summary>
|
/// <param name="str">×Ö·û´®¡£</param>
|
/// <returns></returns>
|
public static Dictionary<string, string> ToDictionary(string str)
|
{
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
if (str == null || str == string.Empty)
|
return dic;
|
|
string[] items = str.Split(new char[1] { ';' });
|
for (int i = 0; i <= items.Length - 1; i++)
|
{
|
if (!items[i].Contains("="))
|
continue;
|
string[] item = items[i].Split(new char[1] { '=' });
|
dic.Add(item[0], item[1]);
|
}
|
|
return dic;
|
}
|
|
/*
|
public static string FromNamedValueCollection(NamedValueItemCollection dic)
|
{
|
if (dic.Count == 0)
|
return string.Empty;
|
|
string rstr = string.Empty;
|
foreach (NamedValueItem item in dic)
|
{
|
rstr += ";" + item.Name + "=" + item.StringValue;
|
}
|
|
if (rstr.Length > 1)
|
rstr = rstr.Substring(1);
|
return rstr;
|
}
|
|
public static NamedValueItemCollection ToNamedValueCollection(string str)
|
{
|
NamedValueItemCollection dic = new NamedValueItemCollection();
|
if (str == null || str == string.Empty)
|
return dic;
|
|
string[] items = str.Split(new char[1] { ';' });
|
for (int i = 0; i <= items.Length - 1; i++)
|
{
|
if (!items[i].Contains("="))
|
continue;
|
string[] item = items[i].Split(new char[1] { '=' });
|
dic.Add(item[0], item[1]);
|
}
|
|
return dic;
|
}
|
*/
|
/// <summary>
|
/// ±í´ïʽֵ½»»»£¬¼´½«Öµ±í´ïʽÖеÄÖµ°´Ãû³ÆÌæ»»µ½Ô´±í´ïʽÖС£
|
/// </summary>
|
/// <param name="srcExpr">Ô´±í´ïʽ,¸ñʽΪ Ãû³Æ=Öµ±í´ïʽÃû³Æ£»Ãû³Æ=Öµ±í´ïʽÃû³Æ</param>
|
/// <param name="valExpr">Öµ±í´ïʽ,¸ñʽΪֵ±í´ïʽÃû³Æ=Öµ;¸ñʽΪֵ±í´ïʽÃû³Æ=Öµ</param>
|
/// <returns>·µ»Øºó±í´ïʽΪ Ãû³Æ=Öµ;Ãû³Æ=Öµ</returns>
|
public static string ExpressionValueExchange(string srcExpr, string valExpr)
|
{
|
string rstr = string.Empty;
|
string[] src = srcExpr.Split(new char[1] { ';' });
|
string[] val = valExpr.Split(new char[1] { ';' });
|
Dictionary<string, string> dval = new Dictionary<string, string>();
|
for (int i = 0; i <= val.Length - 1; i++)
|
{
|
int p = val[i].IndexOf("=");
|
dval.Add(val[i].Substring(0, p), val[i].Substring(p + 1));
|
}
|
|
for (int i = 0; i <= src.Length - 1; i++)
|
{
|
int p = src[i].IndexOf("=");
|
string sn = src[i].Substring(0, p);
|
string sv = src[i].Substring(p+1);
|
|
if (dval.ContainsKey(sv))
|
sv = dval[sv];
|
else
|
sv = string.Empty;
|
|
if (rstr == string.Empty)
|
rstr = sn + "=" + sv;
|
else
|
rstr = rstr+";"+sn + "=" + sv;
|
}
|
|
return rstr;
|
}
|
|
/// <summary>
|
/// ¸ñʽ»¯×Ö·û´®¡£
|
/// </summary>
|
/// <param name="formatText">¸ñʽ»¯×Ö·û´®£¬Öм䲻ÄܰüÀ¨¶ººÅ¡£¸ñʽΪ£º¸ñʽ»¯×Ö·û´®,²ÎÊý×Ö¶ÎÃû1,,²ÎÊý×Ö¶ÎÃû2</param>
|
/// <param name="parameters"></param>
|
/// <returns></returns>
|
public static string FormatString(string formatText, DataRow parameters)
|
{
|
if (parameters == null)
|
return formatText;
|
|
string[] fsParts = formatText.Split(new char[1] { ',' });
|
string[] fparas = new string[fsParts.Length - 1];
|
for (int i = 1; i <= fsParts.Length - 1; i++)
|
{
|
if (parameters.Table.Columns.Contains(fsParts[i]))
|
fparas[i - 1] = parameters[fsParts[i]].ToString();
|
else
|
fparas[i - 1] = string.Empty;
|
}
|
|
string s = string.Format(fsParts[0], fparas);
|
return s;
|
}
|
|
/// <summary>
|
/// »ñÈ¡·Ö¸ô×Ö·û´®Êý×é;È罫"[DBB004]=DAB004;[DBB005]=DAB005;[DBB006]=[DAB009]"·Ö¸ô×Ö·ûÊý×é:DBB004,DAB004,DBB005,DAB005,DBB006,DAB009
|
/// </summary>
|
/// <param name="strValue">Ó³Éä×Ö·û</param>
|
/// <returns>×Ö·û´®Êý×é</returns>
|
public static string[] GetSplitString(string strValue)
|
{
|
if (strValue == null)
|
return null;
|
if (strValue.Length == 0)
|
return null;
|
|
strValue = strValue.Replace("[", "").Replace("]", "");
|
string[] strArray = strValue.Split(new char[2] { ';', '=' });
|
return strArray;
|
}
|
|
/// <summary>
|
/// ¶ÔÎı¾,·Ö¸ôµÄ×Ö·û½øÐÐÌí¼Óµ¥ÒýºÅ,¶ÔÓÚÌõ¼þÊÇinµÄʱºò½øÐÐÌí¼Óµ¥ÒýºÅ
|
/// x022,x023,x025===>'x022','x023','x025'
|
/// </summary>
|
/// <param name="strText">´«ÈëµÄ×Ö·û´®</param>
|
/// <returns>·µ»ØÌí¼Óµ¥ÒýºÅµÄ×Ö·û</returns>
|
public static string AddSingleQuote(string strText)
|
{
|
string[] value = strText.Split(new char[1] { ',' });
|
for (int i = 0; i < value.Length; i++)
|
{
|
string para = value[i];
|
if (para.StartsWith("'"))
|
para = para.Substring(1);
|
if (para.EndsWith("'"))
|
para = para.Substring(0, para.Length - 1);
|
value[i] = "'" + para + "'";
|
}
|
string str = string.Join(",", value);
|
return str;
|
}
|
|
/// <summary>
|
/// Gets the express string.
|
/// </summary>
|
/// <param name="strValue">The STR value.</param>
|
/// <returns></returns>
|
public static string[] GetExpressString(string strValue)
|
{
|
string[] strs = strValue.Split(new char[2] { '=', ' ' });
|
List<string> strList = new List<string>();
|
foreach (string str in strs)
|
{
|
if (str.Contains("["))
|
strList.Add(str);
|
}
|
return strList.ToArray();
|
//return strs.Where(c => c.Contains('[')).ToArray();
|
}
|
|
|
|
/// <summary>
|
/// ¼ìÑéÁ½¸öÊý×ÖÊÇ·ñÏàµÈ
|
/// </summary>
|
/// <param name="x">µÚÒ»¸öÊý×Ö</param>
|
/// <param name="y">µÚ¶þ¸öÊý×Ö</param>
|
/// <returns>·µ»Øtrue£»false</returns>
|
public static bool AboutEqual(double x, double y)
|
{
|
double epsilon = Math.Max(Math.Abs(x), Math.Abs(y)) * 1E-15;
|
return Math.Abs(x - y) <= epsilon;
|
}
|
|
/// <summary>
|
/// ¼ìÑéÊý×ÖÊý×éÊÇ·ñÈ«²¿ÏàµÈ
|
/// ²ÉÓÃÏàµÈ´«µÝµÄ·½·¨£¬ÑéÖ¤Ò»ÂÖ¼´¿É
|
/// </summary>
|
/// <param name="douArrs"></param>
|
/// <returns></returns>
|
public static bool AboutEqual(params double[] douArrs)
|
{
|
double dbFirst = douArrs[0];
|
for (int t = 1; t < douArrs.Length; t++)
|
{
|
if (!AboutEqual(dbFirst, douArrs[t]))
|
return false;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// ×Ö·ûÊý×éÑéÖ¤ÊÇ·ñÓÐΪ¿Õ»òÕßnull
|
/// </summary>
|
/// <param name="objs"></param>
|
/// <returns></returns>
|
public static bool ExistsEmptyOrNull(params object[] objs)
|
{
|
if (objs == null || objs.Length == 0)
|
return true;
|
foreach (object obj in objs)
|
{
|
if (IsNullOrEmptyReturnZero<string>(obj) == "")
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// ·ºÐÍת»»ÎªÊýÖµÀàÐÍ
|
/// </summary>
|
/// <typeparam name="T"></typeparam>
|
/// <param name="obj"></param>
|
/// <returns></returns>
|
public static T IsNullOrEmptyReturnZero<T>(object obj)
|
{
|
if (Equals(obj, null) || Equals(DBNull.Value, obj))
|
{
|
if (typeof(T).FullName == "System.String")
|
return (T)Convert.ChangeType("", typeof(T));
|
return default(T);
|
}
|
try
|
{
|
return (T)Convert.ChangeType(obj, typeof(T));
|
}
|
catch
|
{
|
return default(T);
|
}
|
}
|
|
|
}
|
}
|