import System.*;
public class TrimTest
{
public static void main(String[] args)
{
String temp[] = MakeArray();
Console.WriteLine("Concatenating the inital values in the array,"
+ " we get the string:");
Console.WriteLine("'{0}'{1}", String.Concat(temp),
Environment.get_NewLine());
// trim whitespace from both ends of the elements
for (int i = 0; i < temp.get_Length(); i++) {
temp.set_Item(i, temp[i].Trim());
}
Console.WriteLine("Concatenating the trimmed values in the array,"
+ " we get the string:");
Console.WriteLine("'{0}'{1}", String.Concat(temp),
Environment.get_NewLine());
// reset the array
temp = MakeArray();
// trim the start of the elements. Passing null trims whitespace only
for (int i = 0; i < temp.get_Length(); i++) {
temp.set_Item(i, temp[i].TrimStart(null));
}
Console.WriteLine("Concatenating the start-trimmed values in the "
+ "array, we get the string:");
Console.WriteLine("'{0}'{1}", String.Concat(temp),
Environment.get_NewLine());
// reset the array
temp = MakeArray();
// trim the end of the elements. Passing null trims whitespace only
for (int i = 0; i < temp.get_Length(); i++) {
temp.set_Item(i, temp[i].TrimEnd(null));
}
Console.WriteLine("Concatenating the end-trimmed values in the array,"
+ " we get the string:");
Console.WriteLine("'{0}'", String.Concat(temp));
} //main
private static String[] MakeArray()
{
String arr[] = { " please ", " tell ", " me ",
" about ", " yourself " };
return arr;
} //MakeArray
} //TrimTest