Welcome to fuzzydev Sign in | Join | Help
in Search

.Net

String.Contains(String)

In our .Net 1.1 days we used to check whether a string object contains a specified string(text) using IndexOf method.

Here is the typical code to check the existence of a string in an string object.

//Sample code

string sName = "John Smith";

if(sName.IndexOf("Smith") > -1) {

//Smith exists in string object sName

}

Now let's take a closer look at the above code...... What we want is to know whether an instance of string contains some string(text).

Did I say contains......that's exactly C# .Net 2.0 provides us with.

Let's revisit the same functionality using 2.0

//Sample code 

string sName = "John Smith";

if(sName.Contains("Smith")) {

//Smith exists in string object sName

}

Wallah.....it's so simple and sophisticated.

Published 10 June 2006 by sachinjoshi
Filed Under:
Anonymous comments are disabled

This Blog

Post Calendar

<June 2006>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

Sponsored Links

Syndication

Copyright 2010, Sachin Joshi. All rights reserved.
The content on this site represents my own personal opinions and thoughts at the time of posting, and does not reflect those of my employer's in any way.
Powered by Community Server, by Telligent Systems