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 iunie 2006 by sachinjoshi
Filed Under:
New Comments to this post are disabled

This Blog

Post Calendar

<iunie 2006>
lumamijovidu
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Sponsored Links

Syndication

Copyright 2006, 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