Dave Burke : Freelance .NET Web Developer specializing in Online Communities

StartsWith vrs. Substring(0,#)

I revived an old .ASP function in C# to pass a clean phone number to the DL and happened upon String().StartsWith, a superior method to Substring(0,Some_Int):

Lame

if (phonenum.Substring(0,2) == "1-" || phonenum.Substring(0,2) == "1." || phonenum.Substring(0,2) == "1 " || phonenum.Substring(0,2) == "1(")

Better

if (phonenum.StartsWith("1-") || phonenum.StartsWith("1.") || phonenum.StartsWith("1 ") || phonenum.StartsWith("1("))

Best

Some regex expression... :-)

 

Comments (0) | Post RSS RSS comment feed

Posted on 3/26/2004 7:51:00 PM by Dave Burke
Categories:
Tags: no tags for this post

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke