i was sure this should be easy but here i am. i have a text file with information of the tones required to play the mario theme. i was needing to read line by line and break out the numbers and put them in a array. the problem is i dont know how many digits the numbers will be and as far as i know only a char has a test for if it is a digit. i tried selecting out one char at a time and testing but that didnt work. any ideas?

:beep frequency=660 length=80ms;
:delay 200ms;
:beep frequency=760 length=50ms;
:delay 150ms;
:beep frequency=860 length=100ms;
:delay 300ms;
.....

while((s = sr.ReadLine()) != null)
{
    if ((i = s.IndexOf("beep frequency=")) != -1)
    {
        for (int j = j + 15; ((char)s.Substring(j,1)).IsDigit ; j++)
        {
            //if it is a digit do some crazy stuff here                    
        }
    }
}

You could use the String.Split function to split each line according to where each space is. Then you could just substring from the = signs to get the digits. Something like this (untested but should give you an idea):

while ((s = sr.ReadLine()) != null)
{
  string[] chunks = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  foreach (string part in chunks)
  {
    int i = part.IndexOf("=");
    if (i != -1)
    {
       int digit = Convert.ToInt32(part.Substring(i+1));
       // do something with digit...

    }
  }
}

i guess i could do a 2 stage split. the first one on '=' and the second one one ' '. combined with some tryparsing i could make it work...

Does some program that creates those rules exist?

Friend how to extract that program that creates that!

Exemple:music super mario bross

:beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=510 length=100ms;
:delay 100ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=770 length=100ms;
:delay 550ms;
:beep frequency=380 length=100ms;
:delay 575ms;
:beep frequency=510 length=100ms;
:delay 450ms;
:beep frequency=380 length=100ms;
:delay 400ms;
:beep frequency=320 length=100ms;
:delay 500ms;
:beep frequency=440 length=100ms;
:delay 300ms;
:beep frequency=480 length=80ms;
:delay 330ms;
:beep frequency=450 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 200ms;
:beep frequency=660 length=80ms;
:delay 200ms;
:beep frequency=760 length=50ms;
:delay 150ms;
:beep frequency=860 length=100ms;
:delay 300ms;
:beep frequency=700 length=80ms;
:delay 150ms;
:beep frequency=760 length=50ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 300ms;
:beep frequency=520 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 150ms;
:beep frequency=480 length=80ms;
:delay 500ms;
:beep frequency=510 length=100ms;
:delay 450ms;
:beep frequency=380 length=100ms;
:delay 400ms;
:beep frequency=320 length=100ms;
:delay 500ms;
:beep frequency=440 length=100ms;
:delay 300ms;
:beep frequency=480 length=80ms;
:delay 330ms;
:beep frequency=450 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 200ms;
:beep frequency=660 length=80ms;
:delay 200ms;
:beep frequency=760 length=50ms;
:delay 150ms;
:beep frequency=860 length=100ms;
:delay 300ms;
:beep frequency=700 length=80ms;
:delay 150ms;
:beep frequency=760 length=50ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 300ms;
:beep frequency=520 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 150ms;
:beep frequency=480 length=80ms;
:delay 500ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 220ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=200ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 150ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 420ms;
:beep frequency=585 length=100ms;
:delay 450ms;
:beep frequency=550 length=100ms;
:delay 420ms;
:beep frequency=500 length=100ms;
:delay 360ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 220ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=200ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 150ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 420ms;
:beep frequency=585 length=100ms;
:delay 450ms;
:beep frequency=550 length=100ms;
:delay 420ms;
:beep frequency=500 length=100ms;
:delay 360ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 350ms;
:beep frequency=500 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=430 length=80ms;
:delay 150ms;
:beep frequency=380 length=80ms;
:delay 600ms;
:beep frequency=500 length=60ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 350ms;
:beep frequency=500 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 150ms;
:beep frequency=660 length=80ms;
:delay 550ms;
:beep frequency=870 length=80ms;
:delay 325ms;
:beep frequency=760 length=80ms;
:delay 600ms;
:beep frequency=500 length=60ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 350ms;
:beep frequency=500 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=430 length=80ms;
:delay 150ms;
:beep frequency=380 length=80ms;
:delay 600ms;
:beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=510 length=100ms;
:delay 100ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=770 length=100ms;
:delay 550ms;
:beep frequency=380 length=100ms;
:delay 575ms;

OK, well, this is actually very simple. Here is my example, it is a console appication and it uses a const string of the song paired with a StringReader. However, it should be very easy to adapt it to use a StreamReader.

class Program
    {
        const string Song = @":beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=510 length=100ms;
:delay 100ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=770 length=100ms;
:delay 550ms;
:beep frequency=380 length=100ms;
:delay 575ms;
:beep frequency=510 length=100ms;
:delay 450ms;
:beep frequency=380 length=100ms;
:delay 400ms;
:beep frequency=320 length=100ms;
:delay 500ms;
:beep frequency=440 length=100ms;
:delay 300ms;
:beep frequency=480 length=80ms;
:delay 330ms;
:beep frequency=450 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 200ms;
:beep frequency=660 length=80ms;
:delay 200ms;
:beep frequency=760 length=50ms;
:delay 150ms;
:beep frequency=860 length=100ms;
:delay 300ms;
:beep frequency=700 length=80ms;
:delay 150ms;
:beep frequency=760 length=50ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 300ms;
:beep frequency=520 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 150ms;
:beep frequency=480 length=80ms;
:delay 500ms;
:beep frequency=510 length=100ms;
:delay 450ms;
:beep frequency=380 length=100ms;
:delay 400ms;
:beep frequency=320 length=100ms;
:delay 500ms;
:beep frequency=440 length=100ms;
:delay 300ms;
:beep frequency=480 length=80ms;
:delay 330ms;
:beep frequency=450 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 200ms;
:beep frequency=660 length=80ms;
:delay 200ms;
:beep frequency=760 length=50ms;
:delay 150ms;
:beep frequency=860 length=100ms;
:delay 300ms;
:beep frequency=700 length=80ms;
:delay 150ms;
:beep frequency=760 length=50ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 300ms;
:beep frequency=520 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 150ms;
:beep frequency=480 length=80ms;
:delay 500ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 220ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=200ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 150ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 420ms;
:beep frequency=585 length=100ms;
:delay 450ms;
:beep frequency=550 length=100ms;
:delay 420ms;
:beep frequency=500 length=100ms;
:delay 360ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 220ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=200ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=1020 length=80ms;
:delay 150ms;
:beep frequency=1020 length=80ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=760 length=100ms;
:delay 100ms;
:beep frequency=720 length=100ms;
:delay 150ms;
:beep frequency=680 length=100ms;
:delay 150ms;
:beep frequency=620 length=150ms;
:delay 300ms;
:beep frequency=650 length=150ms;
:delay 300ms;
:beep frequency=380 length=100ms;
:delay 150ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=430 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 100ms;
:beep frequency=570 length=100ms;
:delay 420ms;
:beep frequency=585 length=100ms;
:delay 450ms;
:beep frequency=550 length=100ms;
:delay 420ms;
:beep frequency=500 length=100ms;
:delay 360ms;
:beep frequency=380 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=100ms;
:delay 150ms;
:beep frequency=500 length=100ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 350ms;
:beep frequency=500 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=430 length=80ms;
:delay 150ms;
:beep frequency=380 length=80ms;
:delay 600ms;
:beep frequency=500 length=60ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 350ms;
:beep frequency=500 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 150ms;
:beep frequency=660 length=80ms;
:delay 550ms;
:beep frequency=870 length=80ms;
:delay 325ms;
:beep frequency=760 length=80ms;
:delay 600ms;
:beep frequency=500 length=60ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=500 length=60ms;
:delay 350ms;
:beep frequency=500 length=80ms;
:delay 150ms;
:beep frequency=580 length=80ms;
:delay 350ms;
:beep frequency=660 length=80ms;
:delay 150ms;
:beep frequency=500 length=80ms;
:delay 300ms;
:beep frequency=430 length=80ms;
:delay 150ms;
:beep frequency=380 length=80ms;
:delay 600ms;
:beep frequency=660 length=100ms;
:delay 150ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=510 length=100ms;
:delay 100ms;
:beep frequency=660 length=100ms;
:delay 300ms;
:beep frequency=770 length=100ms;
:delay 550ms;
:beep frequency=380 length=100ms;
:delay 575ms; ";
        static void Main(string[] args)
        {
            System.IO.StringReader r = new System.IO.StringReader(Song);
            while (r.Peek() != -1)
            {
                string Instruction = r.ReadLine().Remove(0,1);
                Console.WriteLine(Instruction);
                if (Instruction.StartsWith("beep"))
                {
                    int start = Instruction.IndexOf('=') + 1;
                    int end = Instruction.IndexOf(' ', start);
                    int freq = int.Parse(Instruction.Substring(start, end - start));
                    start = Instruction.IndexOf('=', end) + 1;
                    end = Instruction.IndexOf('m', start);
                    int dur = int.Parse(Instruction.Substring(start, end - start));
                    Console.Beep(freq, dur);
                }
                else
                {
                    int start = Instruction.IndexOf(' ') + 1;
                    int end = Instruction.IndexOf('m', start);
                    int delay = int.Parse(Instruction.Substring(start, end - start));
                    System.Threading.Thread.Sleep(delay);
                }
            }
        }
    }
This question has already been answered. Start a new discussion instead.