Common function

xiaoxiao2021-03-06  19

///

/// Is the date format correct?

///

#Region Public String IsdateFormat (String StRDATE)

Public string isdateFormat (String strdate)

{

STRDATE = strdate.trim ();

Regex r1 = new regex (@ "^ (? [1-9] [0-9] {0,3}) / (? [0-9] {1, 2}) / (? [0-9] {1, 2}) $ ");

Regex r2 = new regex (@ "^ (? [1-9] [0-9] {0,3}) - (? [0-9] {1, 2}) - (? [0-9] {1, 2}) $ ");

Regex R3 = New Regex (@ "^ (? [1-9] [0-9] {0,3}) year (? [0-9] {1, 2}) month (? [0-9] {1, 2}) Day $ ");

Regex R4 = New Regex (@ "^ (? [0-9] {1, 2}) / (? [0-9] {1, 2}) / (? [1 -9] [0-9] {0,3}) $ ");

// Year, month, day

String year, month, date;

IF (regex.ismatch (@ "^ (? [0-9] {1, 2}) / (? [0-9] {1, 2}) / (? [1-9] [0-9] {3}) $ "))

{

Year = r4.match (strdate) .result ("$ {year}");

Month = r4.match (strdate) .result ("$ {month}");

Date = r4.match (strdate) .Result ("$ {day}");

}

Else IF (regex.ismatch (@ "^ (? [1-9] [0-9] {0,3}) / (? [0-9] {1,2}) / (? [0-9] {1, 2}) $ "))

{

Year = r1.match (strdate) .result ("$ {year}");

Month = r1.match (strdate) .result ("$ {month}");

Date = r1.match (strdate) .Result ("$ {day}");

}

Else IF (regex.ismatch (@ "^ (? [1-9] [0-9] {0,3}) - (? [0-9] {1,2}) - (? [0-9] {1, 2}) $ "))

{

Year = r2.match (strdate) .result ("$ {year}");

Month = r2.match (strdate) .Result ("$ {month}");

Date = r2.match (strdate) .Result ("$ {day}");

}

Else if (stradate, @ "^ (? [1-9] [0-9] {0,3}) year (? [0-9] {1,2}) Month (? [0-9] {1, 2}) day $ ")) {

Year = r3.match (strdate) .result ("$ {year}");

Month = r3.match (strdate) .result ("$ {month}");

Date = r3.match (strdate) .Result ("$ {day}");

}

Else

{

Return "Error";

}

// Last check of the date of the date

Try

{

System.datetime DT = New DateTime (Convert.Toint32 (Year), Convert.Toint32 (Month), Convert.Toint32 (Date);

Return Dt.toString ("YYYY-MM-DD");

}

Catch

{

Return "Error";

}

}

#ndregion

-------------------------------------------------- ----------------------------------------

///

/// Test if the Email string format is correct

///

#Region Public Bool ISEMAILFORMAT (String Stree)

Public Bool IsemailFormat (String Stree)

{

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 }) (/]?) $ ");

}

#ndregion

-------------------------------------------------- ----------------------------------------

///

/// Convert Fifteen ID cards to the 18th function.

///

#REGON PUBLIC STRING ConvertIDCARD15TO18 (String Strtemp)

Public String ConvertIDCARD15TO18 (String Strtemp)

{

Int [] arrint = new int [] {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};

String arrCh = "10x98765432";

INT NTEMP = 0;

IF (strTemp.length == 15)

{

Strtemp = startemp.substring (0,6) "19" strTemp.substring (6, strTemp.length-6);

For (int i = 0; i

{

Ntemp = int.parse (strtemp.substring (i, 1) .tostring ()) * arrint [i];

}

STRTEMP = Arrch [ntemp% 11];

}

Char DD = Arrch [NTEMP% 11]; RETURN STRTEMP;

}

#ndregion

-------------------------------------------------- ----------------------------------------

In order to determine the function group of the ASCII code, only support

///

/ / Is whether it is a double-byte character.

///

Public Static Bool Istwobyteschar (Char CHR)

{

String str = chr.tostring ();

// Use Chinese to support the encoding

Encoding ecode = encoding.getencoding ("GB18030");

IF (ecode.getbytecount (str) == 2)

{

Return True;

}

Else

{

Return False;

}

}

///

/// get the ASCII code of the character

///

Public Static Int ASCII (Char CHR)

{

Encoding ecode = encoding.getencoding ("GB18030");

Byte [] codebytes = ecode.getbytes (chr.tostring ());

IF (ISTWOBYTESCHAR (CHR))

{

// Double-nature code is high by 256, plus low

/ / Should be no symbol, then reduce 65536

Return (int) codebytes [0] * 256 (int) codebytes [1] - 65536;

}

Else

{

Return (int) codebytes [0];

}

}

转载请注明原文地址:https://www.9cbs.com/read-42471.html

New Post(0)