Posted by: R Manimaran | February 12, 2007

String Functions in C#

There is no function for Left,Right and Mid in C#. We have to write our own function to get this functionality, and here is the functions

public static string Mid(string param,int startIndex, int length)
{
 //start at the specified index in the string ang get N number of
 //characters depending on the lenght and assign it to a variable
 string result = param.Substring(startIndex, length);
 //return the result of the operation
 return result;
}

public static string Mid(string param,int startIndex)
{
 //start at the specified index and return all characters after it
 //and assign it to a variable
 string result = param.Substring(startIndex);
 //return the result of the operation
 return result;
}
public static string Right(string param,int Length)
{
 string result=param.Substring(param.Length -Length,Length);
 return result;
}
public static string Left(string Param,int Length)
{
 string result=Param.Substring(0,Length);
 return result;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: