String Control class

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. IO;
Using system. Web;
Using system. Web. UI;
Using system. xml;
Using system. drawing;
Using system. configuration;
Using system. Web. UI. webcontrols;
Using system. Text. regularexpressions;
Using system. Security. cryptography;

Namespace classlibrary
{
# Region string control class
/// <Summary>
/// String control class
/// </Summary>
Public static class controlstring
{
# Region message function

# region display prompt message
///


// display prompt message
///
/ // data to be displayed
// page class
Public static void showmessagebox (string str_message, page)
{< br> type cstype = page. getType ();
clientscriptmanager cs = page. clientscript;
CS. registerstartupscript (cstype, "", "alert ('" + str_message + "');", true);

}
# Endregion

# Region display the message and direct it to the target page
/// <Summary>
/// Display the message and direct it to the target page
/// </Summary>
/// <Param name = "str_message"> display data </param>
/// <Param name = "url"> target path </param>
/// <Param name = "page"> page class </param>
Public static void showmessageboxredirect (string str_message, string URL, page)
{
Type cstype = page. GetType ();
Clientscriptmanager cs = page. clientscript;
CS. registerstartupscript (cstype, "", "alert ('" + str_message + "'); window. Location. href = '" + URL + "';", true );
}
# Endregion

# Region display and close this window
/// <Summary>
/// Display information and close this window
/// </Summary>
/// <Param name = "str_message"> display data </param>
/// <Param name = "page"> page class </param>
Public static void showmessageboxandclosewindow (string str_message, page)
{
Type cstype = page. GetType ();
Clientscriptmanager cs = page. clientscript;
CS. registerstartupscript (cstype, "", "alert ('" + str_message + "'); window. Close ();", true );
}
# Endregion

# Region display information window and move back
/// <Summary>
/// Display the information window and move back
/// </Summary>
/// <Param name = "str_message"> display data </param>
/// <Param name = "page"> page class </param>
Public static void showmessageboxgoback (string str_message, page)
{
Type cstype = page. GetType ();
Clientscriptmanager cs = page. clientscript;
CS. registerstartupscript (cstype, "", "alert ('" + str_message + "'); window. History. Go (-1);", true );
}
# Endregion

# Endregion

# Region get length Function

# Region obtain a string of the specified length
/// <Summary>
/// Obtain the specified length string
/// </Summary>
/// <Param name = "str"> raw data </param>
/// <Param name = "count"> obtain the length </param>
/// <Returns> return data </returns>
Public static string getlimitstr (string STR, int count)
{
If (Str. length> count)
STR = Str. substring (0, count );
Return STR;
}
# Endregion

# Region obtain the first n strings
/// <Summary>
/// Obtain the first n strings
/// </Summary>
/// <Param name = "str"> raw data </param>
/// <Param name = "N"> specify the length </param>
/// <Returns> return data </returns>
Public static string getnstring (string STR, int N)
{
Int INTN = N;
If (INTN <1) {INTN = 1 ;}

String tmpstr = STR;
Char [] cc = tmpstr. tochararray ();
Int intlen = tmpstr. length;
Int I;
For (I = 0; I <cc. length; I ++)
{
If (system. convert. toint32 (CC [I])> 255 | (system. convert. toint32 (CC [I])> 64 & system. convert. toint32 (CC [I]) <91 ))
{
Intlen ++;
}
}
If (intlen> N)
{
Tmpstr = tmpstr. substring (0, tmpstr. Length-1 );
Tmpstr = getnstring (tmpstr, INTN );
}

Return tmpstr;
}
# Endregion

# Endregion
}
# Endregion
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.