justanswerthequestion
justanswerthequestion

Reputation: 13

Finding where a string is in a string

So I have a string for example 0010101101010101010101010111100010101010011010 and I have this string 111000 I want to find out where this string is in the string for example, 111000 would be around 26 numbers in.

0010101101010101010101010111100010101010011010

-------------------------------------------111000

                         ^26

I would then take that 26 and do something with it

Do I need to do the string searching manually, by taking the first leter off and doing string.startswith(111000) or is there a way to find out like a built in method? regex perhaps? string builder?

Upvotes: 1

Views: 72

Answers (1)

GregoryHouseMD
GregoryHouseMD

Reputation: 2378

string longString = "the stirng with zeros and ones";
string searchString = "111000";
int startIndex = longString.IndexOf(searchString);

If you apply this to your examples, startIndex will be 25 as it is zero based.

Upvotes: 2

Related Questions