String Comparison

This is a discussion on String Comparison within the C# Programming forums, part of the General Programming Boards category; I am trying to help a friend of mine with a c# assignment and I can't figure out why when ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    1

    String Comparison

    I am trying to help a friend of mine with a c# assignment and I can't figure out why when I read in a series of 3 character strings and compare them to predetermined values, that it keeps coming up 0. I haven't done c# in a while and my mind is boggled.

    Code:
            private void btnRead_and_Count_Starts_Click(object sender, EventArgs e)
            {
                StreamReader reader = new StreamReader(openFile.FileName);
                int countS = 0;
                int countStop = 0;
                int count = 0;
                string s = "";
                string print = "";
                string print2 = "";
                do
                {
                    s = reader.ReadLine();
                    switch (s)
                    {
                        case "aug":
                            MessageBox.Show("hi");
                            countS++;
                            break;
                        case "gug":
                            countS++;
                            break;
                        case "uug":
                            countS++;
                            break;
                        case "uag":
                            countStop++;
                            break;
                        case "uga":
                            countStop++;
                            break;
                        case "uaa":
                            countStop++;
                            break;
                        default:
                            count++;
                            break;
                    }
                }
                while (!reader.EndOfStream);
                reader.Close();
                print = "Start Codons: " + countS;
                print2 = "Stop Codons: " + countStop;
                lstDNA.Items.Add(print);
                lstDNA.Items.Add(print2);
            }
        }
    It just refuses to ever count anything for countS and countStop.

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    What's the result of "count" at the end?
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String comparison.
    By zigbigidorlu in forum C Programming
    Replies: 1
    Last Post: 04-01-2010, 01:08 PM
  2. std::string comparison versus int comparison
    By leeor_net in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2009, 08:28 AM
  3. String Comparison
    By kpreston in forum C Programming
    Replies: 16
    Last Post: 10-20-2008, 08:43 PM
  4. String Comparison
    By Cdrwolfe in forum C++ Programming
    Replies: 8
    Last Post: 03-27-2006, 10:59 AM
  5. using a string comparison in C
    By mr. J in forum C Programming
    Replies: 4
    Last Post: 05-09-2003, 06:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21