Learning to use the "string" (6) of ASP. NET: stringinfo class

Source: Internet
Author: User
After learning this class, I don't feel it will be of any use. The same operation is not as convenient as in the string class, but also using system. Globalization;
Main members:
 
/* Static Method */stringinfo. getnexttextelement (); // gets the specified element. By default, stringinfo is the first element. gettextelementenumerator (); // gets the stringinfo enumerator. parsecombiningcharacters (); // obtain the int []/* attribute */lengthintextelements composed of serial numbers; // The number of elements; read-only string; // the string of the object; read/write/* object Method */substringbytextelements (); // truncate a string
Constructors and attributes:
Protected void button1_click (Object sender, eventargs e) {stringinfo Sf = new stringinfo ("abcdefg"); int n1 = SF. lengthintextelements; // 7 string S1 = SF. string; // abcdefg textbox1.text = string. concat (N1, "\ n", S1);} protected void button2_click (Object sender, eventargs e) {stringinfo Sf = new stringinfo (); int n1 = SF. lengthintextelements; // 0 string S1 = SF. string; // SF. string = "ABC"; int n2 = SF. lengthintextelements; // 3 string S2 = SF. string; // ABC textbox1.text = string. concat (N1, "\ n", S1, "\ n" + N2, "\ n", S2 );}
Substringbytextelements () method:
Protected void button1_click (Object sender, eventargs e) {stringinfo Sf = new stringinfo ("abcdefg"); string S1 = SF. substringbytextelements (2); // cdefg string S2 = SF. substringbytextelements (2, 3); // CDE textbox1.text = S1 + "\ n" + S2 ;}
Three static methods:
// Stringinfo. getnexttextelement () protected void button#click (Object sender, eventargs e) {string S1 = stringinfo. getnexttextelement ("abcdefg"); // a string S2 = stringinfo. getnexttextelement ("abcdefg", 1); // B textbox1.text = S1 + "\ n" + S2;} // stringinfo. parsecombiningcharacters () protected void button2_click (Object sender, eventargs e) {int [] narr = stringinfo. parsecombiningcharacters ("ASP. net "); textbox1.text = string. join (",", narr); // 0, 1, 2, 3, 4, 5, 6} // stringinfo. gettextelementenumerator (); Use ienumerator requires using system. colleator; protected void button3_click (Object sender, eventargs e) {string STR = "abcdefg"; string S1, S2; S1 = S2 = ""; ienumerator e1 = stringinfo. gettextelementenumerator (STR); While (e1.movenext () {S1 + = string. format ("{0}", e1.current); // a B c d e f g} ienumerator e2 = stringinfo. gettextelementenumerator (STR, 2); While (e2.movenext () {S2 + = string. format ("{0}", e2.current); // c d e f g} textbox1.text = S1 + "\ n" + S2 ;}
Related Article

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.