Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# if String Contains 2 "hallo" [duplicate]

Tags:

string

c#

Possible Duplicate:
How would you count occurences of a string within a string (C#)?

I want to check if a String contains 2 things..

String hello = "hellohelloaklsdhas";

if hello.Contains(*hello 2 Times*); -> True

How can I solve this?

like image 240
eMi Avatar asked Nov 08 '11 16:11

eMi


1 Answers

You could use a regex :)

return Regex.Matches(hello, "hello").Count == 2;

This matches the string hello for the pattern "hello" and returns true if the count is 2.

like image 92
Ray Avatar answered Oct 04 '22 21:10

Ray