ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

FristChar

Select Frist character in string .

Source

public static class MehrdadExtensions
{
    public static string FristChar(this string input)
    {
        if (!string.IsNullOrEmpty(input))
        {
            if (input.Length >= 1)
            {
                return input.Substring(0, 1);
            }
            else
            {
                return input;
            }
        }
        else
        {
            return null;
        }

    }
}

Example

string name = "mehrdad";
Response.Write("Name is : " + name);
Response.Write("<br />");
Response.Write("Frist Char : "+name.FristChar());

Author: Mehrdad Ghasemi

Submitted on: 28 mrt. 2009

Language: C#

Type: System.String

Views: 4567