Operations on strings

Source: Internet
Author: User
The earthquake just happened. It may be too small. I don't feel it ~~~~~
Today, I calmly learned some operations on strings. I want to use them, so even though they are all the most basic operations, remember them.
Including:
1. Comparison string: Compare, compareto, equals, = ,! =
2. Positioning characters and substrings: startwith/endswith, indexof/lastindexof, indexofany/lastindexofany
3. format the string: Format
4. connection string: Concat, join, +
5. Split string: Split
6. insert and fill strings: insert, padleft/pagright
7. Delete and cut strings: Remove, TRIM/trimstart/trimend
8. Copy strings: Copy and copyto
9. Replace string: replace
10. Change the case sensitivity: toupper/tolower
Code As follows: Class Program
{

Static   Void Main ( String [] ARGs)
{
Console. writeline ( " ------------------- Test join " );
String Str =   "" ;
String [] strarr =   {"Aaa","Bbb","CCC"} ;
Str = String. Join ( " + " , Strarr );
Console. writeline (STR );

Console. writeline ( " ------------------- Test format " );
String stra =   " Hello " ;
String strb =   " World " ;
Str = String. Format ( " {0}, {1 }! " , Stra, strb );
Console. writeline (STR );

Console. writeline ( " ------------------- Test compareto " );
Console. writeline (stra. compareto (strb ));

Console. writeline ( " ------------------- Test indexof " );
Console. writeline (Str. indexof ( ' L ' ));

Console. writeline ( " ------------------- Test split " );
Strarr = Str. Split ( ' + ' );
Int I = 0 ;
While (I < Strarr. length) {
Console. writeline (strarr [I]);
I++;
}

Console. writeline ( " ------------------- Test padleft " );
Str =   " Hello " ;
Str = Str. padleft ( 20 , ' * ' );
Console. writeline (STR );

Console. writeline ( " ------------------- Test remove " );
Str =   " Abcdefg " ;
Str = Str. Remove ( 1 , 3 );
Console. writeline (STR );

Console. writeline ( " ------------------- Test trim " );
Str =   " % Hello & $ # " ;
Char [] Trmchar = {'%','&','$','#'} ;
Str = Str. Trim (trmchar );
Console. writeline (STR );
}
}

Next, let's look at stringbuilder.

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.