Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reg ex first two char

Status
Not open for further replies.

deejayAr

Technical User
Mar 20, 2008
126
US
can any one help me
I need regex to find first 2 character in word (string)

thanks
 
it's not regex, but
Code:
public string FirstTwo(string s)
{
   var two = s.Take(2).ToArray();
   return string.Join("", two);
}
or
Code:
public IEnumerable<string> FirstTwo(string s)
{
   return s.Split(' ').SelectMany(x=>
            {
              var two = x.Take(2).ToArray();
              return string.Join("", two);
            });
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top