C# Instring Function

C# Instring Function

The IndexOf method can be used to find whether a string exists in another string. 

sample code:

string str1 = “welcome”;

string str2 = “come”; 

int pos = str1.IndexOf(str2)
if pos is not equal to -1 then the search string str2 exists in the given string str1. Else the string does not exist.

Note: The string.Contains method can also be used to find the instring but it is not supported in dotnet framework version1 whereas IndexOf is supported in version1 and version2 as well.


Leave a Reply

You must be logged in to post a comment.

All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.