/// <Summary>
/// Obtain the IP address of the site user
/// </Summary>
/// <Returns> </returns>
Public static string getuserip ()
{
Return httpcontext. Current. Request. servervariables ["remote_addr"]. tostring ();
}
/// <Summary>
/// Remove the last ',' sign of the string
/// </Summary>
/// <Param name = "CHR">: string to be processed </param>
/// <Returns> returns the processed string </returns>
Public static string lost (string CHR)
{
If (CHR = NULL | CHR = string. Empty)
{
Return "";
}
Else
{
CHR = CHR. Remove (CHR. lastindexof (","));
Return CHR;
}
}
///
// remove the first '/' of the string
///
// string to be processed
// returns the processed string
Public static string lostfirst (string CHR)
{< br> string flg = "";
If (CHR! = String. Empty | CHR! = NULL)
{< br> If (CHR. substring (0, 1) = "/")
flg = CHR. replace (CHR. substring (0, 1), "");
else
flg = CHR;
}< br> return flg;
}
///
// Replace special characters in HTML
///
/// text to be replaced.
// the replaced text.
Public static string htmlencode (string thestring)
{< br> thestring = thestring. replace (">", ">");
thestring = thestring. replace ("<", "<");
thestring = thestring. replace ("", "");
thestring = thestring. replace ("", "");
thestring = thestring. replace ("\" "," ");
thestring = thestring. replace ("\ '", "'");
thestring = thestring. replace ("\ n", "
");
return thestring;
}
/// <Summary>
/// Restore special characters in HTML
/// </Summary>
/// <Param name = "thestring"> the text to be restored. </Param>
/// <Returns> restored text. </Returns>
Public static string htmldiscode (string thestring)
{
Thestring = thestring. Replace (">", "> ");
Thestring = thestring. Replace ("<", "<");
Thestring = thestring. Replace ("","");
Thestring = thestring. Replace ("","");
Thestring = thestring. Replace (""","\"");
Thestring = thestring. Replace ("'","\'");
Thestring = thestring. Replace ("<br/>", "\ n ");
Return thestring;
}
/// <Summary>
/// Generate random numbers
/// </Summary>
/// <Param name = "length"> generation length </param>
/// <Returns> </returns>
Public static string number (INT length)
{
Return number (length, false );
}
///
// generate a random number
///
/// generation length
// whether to block the current thread before generation to avoid duplication
///
Public static string number (INT length, bool sleep)
{< br> If (sleep)
system. threading. thread. sleep (3);
string result = "";
system. random random = new random ();
for (INT I = 0; I {< br> result + = random. next (10 ). tostring ();
}< br> return result;
}