Tim Clark
Experienced Business Owner, Chief Information Officer, Vice President, Chief Software Architect, Application Architect, Project Manager, Software Developer, Senior Web Developer, Graphic Designer & 3D Modeler, University Instructor, University Program Chair, Academic Director.
Specialties: Ruby, Ruby on Rails, JavaScript, JQuery, AJAX, Node.js, React.js, Angular.js, MySQL, PostgreSQL, MongoDB, SQL Server, Responsive Design, HTML5, XHTML, CSS3, C#, ASP.net, Project Management, System Design/Architecture, Web Design, Web Development, Adobe CS6 (Photoshop, Illustrator)
View all posts by Tim Clark
Thanks, this looks useful!
LikeLike
Thanks mate this is what I was looking for !
LikeLike
Even shorter and more flexible:
public static bool Contains(this String item, String subString, StringComparison comparison)
{
return item.IndexOf(item, comparison) != -1;
}
//Ooops, previous was wrong;)
LikeLike
Even shorter and more flexible:
public static bool Contains(this String item, String subString, StringComparison comparison)
{
return item.IndexOf(item, comparison) == -1;
}
LikeLike
subString
LikeLike
Hey Sectoid, whats up with the extra parameter “String subString” its not being used within the method logic? Let us know we are curious.
LikeLike
Way to get all the examples in the comments wrong guys.
It shoud be != -1, and subString should be used instead of item as the first parameter of IndexOf
LikeLike
Best of both worlds (flexibility and terse syntax)
public static bool Contains(this string source, string value, StringComparison comparisonType)
{
return source.IndexOf(value, comparisonType) != -1;
}
public static bool Contains(this string source, string value, bool ignoreCase)
{
return ignoreCase ? source.Contains(value, StringComparison.InvariantCultureIgnoreCase) : source.Contains(value, StringComparison.InvariantCulture);
}
LikeLike
Thanks for this post….
But is this approach faster than converting the string to .ToLower() and then comparing???
LikeLike