Code
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace CSharp
{
Public class TestString
{
Public TestString ()
{
String [] sA = new string [5] {"H", "e", "l", "l", "o "};
Console. WriteLine (String. Concat (sA ));
Console. WriteLine (String. Join ("-", sA ));
String s = String. Join ("", sA );
Console. WriteLine (s );
Char [] c = s. ToCharArray ();
String sl = s. ToLower ();
String su = s. ToUpper ();
Console. WriteLine (sl + "--" + su );
String s2 = s. PadLeft (10 ,'_');
Console. WriteLine (s2 );
String s3 = s. PadRight (10 ,'_');
Console. WriteLine (s3 );
String s4 = String. Join ("-", sA );
String [] s5 = s4.Split (new char [] {'-'});
Foreach (string s6 in s5)
{
Console. WriteLine (s6 );
}
String s7 = s2.Trim ();
Console. WriteLine (s7 );
String s8 = s2.Trim (new char [] {'_'});
Console. WriteLine (s8 );
// TrimEnd, TrimStart is the same.
If (s2.StartsWith ("H "))
{
Console. WriteLine ("S2 was start with 'h '");
}
Else
{
Console. WriteLine ("S2 wasn't start with 'h '");
}
If (s2.EndsWith ("o "))
{
Console. WriteLine ("S2 was end with 'O '");
}
Else
{
Console. WriteLine ("S2 wasn't end with 'O '");
}
Console. WriteLine (s2.Substring (5, s2.Length-5 ));
Console. WriteLine (s2.Remove (0, 5 ));
Console. WriteLine (s2.Replace ("l", "I "));
If (String. IsNullOrEmpty (s2 ))
{
Console. WriteLine ("S2 Is NullOrEmpty ");
}
Else
{
Console. WriteLine ("S2 isn' t NullOrEmpty ");
}
}
}
}