how to check that string contains substring? 
Author Message
 how to check that string contains substring?

Hi!

How to check that some string contains substring?

For example
String strMain = "Hello world"
String strSub = "wor";

What function in C# will tell me that strMain contains strSub?

Thanks.



Tue, 19 Apr 2005 20:35:10 GMT  
 how to check that string contains substring?
Try that's an array.


Quote:
> Hi!

> How to check that some string contains substring?

> For example
> String strMain = "Hello world"
> String strSub = "wor";

> What function in C# will tell me that strMain contains strSub?

> Thanks.



Tue, 19 Apr 2005 20:48:48 GMT  
 how to check that string contains substring?
Inline comments.

Chris R.


Quote:
> Hi!

> How to check that some string contains substring?

> For example
> String strMain = "Hello world"
> String strSub = "wor";

int strIndex = strMain.IndexOf( strSub);

// strIndex will be the 0 based index of the string.
// If there is no match, it returns -1.
// This would return 6 for your example.

Quote:

> What function in C# will tell me that strMain contains strSub?

> Thanks.



Tue, 19 Apr 2005 20:58:29 GMT  
 how to check that string contains substring?

Quote:

> How to check that some string contains substring?

> For example
> String strMain = "Hello world"
> String strSub = "wor";

> What function in C# will tell me that strMain contains strSub?

See String.IndexOf(String)

--

http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too



Tue, 19 Apr 2005 20:51:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. checking if a string contains a letter

2. to check if a CStringArray contains one string?

3. Getting Substring from String.LastIndexOf

4. Finding occurance of a substring in a string in C#

5. Searching string for substring question

6. How to do substring function for C string

7. longest substring in a string

8. How to remove a substring from a string

9. How to insert a substring in a string?

10. substring in a string

11. about searchin' substring in a string

12. How can I extract the substring of string??

 

 
Powered by phpBB® Forum Software