What is meant by TRIM() ?

 Posted by Bharathi Cherukuri on 4/26/2012 | Category: .NET Framework Interview questions | Views: 1392 | Points: 40
Answer:

TRIM() helps us to remove the off spaces characters from the beginning and from the end of the instance.

Example:

using System;


public class Example
{
public static void Main()
{
Console.Write("Enter your first name: ");
string firstName = Console.ReadLine();

Console.Write("Enter your middle name or initial: ");
string middleName = Console.ReadLine();

Console.Write("Enter your last name: ");
string lastName = Console.ReadLine();

Console.WriteLine();
Console.WriteLine("You entered '{0}', '{1}', and '{2}'.",
firstName, middleName, lastName);

string name = ((firstName.Trim() + " " + middleName.Trim()).Trim() + " " +
lastName.Trim()).Trim();
Console.WriteLine("The result is " + name + ".");
}
}


// The following is possible output from this example:
// Enter your first name: John
// Enter your middle name or initial:
// Enter your last name: Doe
//
// You entered ' John ', '', and ' Doe'.
// The result is John Doe


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response