1
Answer

[C#] Match all cases of a string

Jay S

Jay S

10y
981
1
Hi All,

I have a Array of bytes which I am trying to find all the matches of a specific string and store the location (index) of where its found in a list.

So far I have:

                using (BinaryReader br= new BinaryReader(File.Open(this.path, FileMode.Open), Encoding.ASCII))
                {
                    byte[] Name1 = br.ReadBytes(5000000);
                    int nCount = Name1.Count();
                    string humanSName = "Foo";
                    List<int> matches = new List<int>();

                    for (i = 0; i < nCount; i++)
                    {
                        Match mdiv = Regex.Match(Encoding.ASCII.GetString(Name1), humanSName);
                        if (mdiv.Success)
                        {
                            int xx = mdiv.Index;
                            matches.Add(xx); 
                        }
 
                    }
                }

This doesn't seem to work as it only ever matches the first one it finds...like its almost started off back at the start of the byte array.

Any help would be appriciated.
Answers (1)