|
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Text;
Namespace EC
{
///
Common function base class
///
public class Funobject
{
#region Replacement string
///
Features: Replacing characters
///
String
Replace the ' string
public static string Filtersql (String strvalue)
{
String str = "";
str = strvalue.replace ("" "," ");
return str;
}
#endregion
#region Convert HTML operations on the contents of a table Form.
///
Function: Transforms HTML operations on the contents of a table Form,
///
HTML string
///
public static string Htmlcode (String fstring)
{
String str = "";
str = fstring.replace (">", ">");
str = fstring.replace ("<", "<");
str = Fstring.replace ("", "");
str = Fstring.replace ("n", "
");
str = fstring.replace ("R", "
");
str = fstring.replace ("rn", "
");
return str;
}
#endregion
#region Judge whether: return value: √orx
///
Judge whether: Return value: √orx
///
True or False
√orx
public static string judgement (bool B)
{
string s = "";
if (b = = true)
s = "√";
Else
s = "X";
return s;
}
#endregion
#region Intercept string
///
///feature: Intercept string length
///
///the string to intercept
///string length
///true: Add ..., flase: no
// /
public static string GetString (string str, int length, bool flg)
{
int i = 0, j = 0;
foreach (char chr in str)
{
if ((int) CHR > 127)
{
i = 2;
}
Else
{
i++;
}
if (i > Length)
{
str = str. Substring (0, J);
if (FLG)
str + = "...";
break;
}
J + +;
}
return str;
}
#endregion
#region Intercept string + ...
///
Intercept string + ...
///
///
///
///
public static string Cutstring (string strinput, int intlen)/intercept string
{
ASCIIEncoding ASCII = new ASCIIEncoding ();
int intlength = 0;
String strstring = "";
Byte[] s = ASCII. GetBytes (strinput);
for (int i = 0; i < s.length; i++)
{
if ((int) s[i] = = 63)
{
Intlength + 2;
}
Else
{
Intlength + 1;
}
Try
{
Strstring + + strinput.substring (i, 1);
}
Catch
{
Break
}
if (Intlength > Intlen)
{
Break
}
}
If it's truncated, add half an ellipsis.
byte[] MyByte = System.Text.Encoding.Default.GetBytes (strinput);
if (MyByte. Length > Intlen)
{
strstring + = "...";
}
return strstring;
}
#endregion
#region String Division function
///
///String Division
///
///
///
///
///
public string stringsplit (str ing strings, int index, string separ)
{
String[] s = strings. Split (char. Parse (Separ));
return S[index];
}
#endregion
#region exploded string as an array
///
///string function
///
///The string to be decomposed
///delimiter, which can be a string type
///character list
Public Static string[] Splitstr (String str, string splitstr)
{
if (splitstr!= "")
{
System.Collections.Array List C = new System.Collections.ArrayList ();
while (true)
{
int thissplitindex = str. IndexOf (SPLITSTR);
if (thissplitindex >= 0)
{
C.add (str. Substring (0, Thissplitindex));
str = str. Substring (Thissplitindex + splitstr). Length);
}
Else
{
C.add (str);
break;
}
}
string[] D = new String[c.count];
for (int i = 0; i < C.count i++)
{
D[i] = c[i]. ToString ();
}
return D;
}
Else
{
return new string[] {str};
}
}
#endregion
#region URL Encoding
///
URL encoding
///
String
///
public static string urlencoding (String str)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes (str);
Return System.Text.Encoding.UTF8.GetString (bytes). ToString ();
}
#endregion
#region Get the Configuration field value in Web.config
///
Get Global configuration parameters
///
Key Name
Parameters
public static string Getapp (String key)
{
System.Configuration.AppSettingsReader appr = new System.Configuration.AppSettingsReader ();
Try
{
String str = (string) appr. GetValue (Key, typeof (String));
if (str = NULL | | | str = = "") return null;
return str;
}
catch (Exception E) {}
return null;
}
#endregion
#region returns a bit based on whether the passed-in string is yes/no
///
Returns a bit based on whether the passed-in string is yes/no
///
///
///
public static int Getbitbool (string flg)
{
int str = 0;
Switch (FLG. ToLower ())
{
Case "Yes":
str = 1;
Break
Case "No":
str = 0;
Break
Default
Break
}
return str;
}
#endregion
#region HTML Encoding
///
HTML encoding
///
///
///
public static string HtmlEncode (String strinput)
{
String str;
Try
{
str = HttpContext.Current.Server.HtmlEncode (strinput);
}
Catch
{
str = "Error";
}
return str;
}
///
HTML decoding
///
///
///
public static string HtmlDecode (String strinput)
{
String str;
Try
{
str = HttpContext.Current.Server.HtmlDecode (strinput);
}
Catch
{
str = "Error";
}
return str;
}
#endregion
#region detects whether a character character, exists in another character, exists, returns True, or returns false
///
Detects a character character, whether it exists in another character, exists, returns True, or returns false
///
Raw string
Target string
///
public static bool Isenglish (string srcstring, String aimstring)
{
bool Rev. = true;
String Chr;
if (aimstring = = "" | | Aimstring = = null) return false;
for (int i = 0; i < aimstring.length; i++)
{
CHR = aimstring.substring (i, 1);
if (Srcstring.indexof (CHR) < 0)
{
return false;
Break
}
}
return Rev;
}
#endregion
#region detect if the string contains Chinese and Chinese length
///
Detect if the string contains Chinese and Chinese length
///
The string to detect
Chinese string length
public static int cnstringlength (String str)
{
ASCIIEncoding n = new ASCIIEncoding ();
Byte[] B = n.getbytes (str);
int l = 0; L is the actual length of the string
for (int i = 0; I <= b.length-1; i++)
{
if (b[i] = = 63)//Judge whether it is Chinese character or full foot symbol
{
l++;
}
}
return l;
}
#endregion
#region take a few characters to the right of the string
///
Take a few characters to the right of the string
///
String
Several characters to the right
///
public static string Getstrright (string str, int length)
{
String Rev = "";
if (str. Length < length)
{
Rev = str;
}
Else
{
Rev = str. Substring (str. Length-length, length);
}
return Rev;
}
#endregion
#region Replace the string on the right
///
Replace the string on the right
///
String
String to the right
The string to be replaced with
///
public static string Repstrright (String str, string strsrc, String straim)
{
String Rev = "";
if (Getstrright str, strsrc. Length)!= strsrc)
{
Rev = str;
}
Else
{
Rev = str. Substring (0, str. Length-strsrc. Length). ToString () + Straim. ToString ();
}
return Rev;
}
#endregion
}
}
|