Search code examples
c#stringsearch.net-micro-framework

How to find a pair of chars within a string in c# netMF?


This has probably (somewhere) been asked before, but can't find any documentation on it (i have looked!).

Say I had declared a string like:

String Test = "abcdefg";

How would i go about searching the string to see if I could see "cd" anywhere in the string by searching through the string in pairs, like:

{ab}{bc}{cd}{de}{ef}{fg}

That is, if I split each of the values up, and searched for a pair of chars next to each other? Is there a built in function for this?

I have thought about using a char array for this, but it seems to (logically) be very 'heavy'/'slow'. Would there be a better solution to search this string?

EDIT 1

Once I see this "cd", I would then need to doSomething() at that position (which I have already implemented by using the substring method.


Solution

  • Try this.

    String.IndexOf(...) != -1
    

    For more infö, read here.