1 Replies - 693 Views - Last Post: 13 October 2012 - 06:03 AM Rate Topic: -----

#1 ApacheOmega  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-October 12

How to append selected array elements to a string for cout like in C++

Posted 13 October 2012 - 05:27 AM

I'm trying to recreate a program I made with C++ int a C# windows form program I have the bulk of it done but there's one small thing thats keeping the program from working like it should.
**my program is a bionformatics program that allows the user to either enter a string/sequence of DNA or RNA characters and the program converts it into the corresponding protein/amino acid and prints out an amino acid/protein for every codon the program sees so if I input "AAA GGG CCC" it prints out "Lysine Glycine Proline"**

this is the snippet of code I'm having trouble with in the c++ version
    for (i=0; i<numberOfCodons;i++)
	{
		
		endIndex=beginIndex+3;
		codon="";
		
		{


//here is where I'm having the trouble converting this to C# and have it cout the write
//way
   
    codon.append(RNA.substr(beginIndex,endIndex-beginIndex));

		}
		for (k=0;k<64;k++)
		{
			if(codon==codons[k])
			{


//here is where I'm having the trouble converting this to C# and have it cout the write way
like I metioned previously AAA GGG CCC couts Lysine Glycine Proline
   
    protein.append(aminoAcids[k]);
				
			}
			
		}
		beginIndex+=3;
	}
	cout<<protein<<endl;
	protein.clear();


here's what I have in c# so far
    private void Tranlate_Click(object sender, EventArgs e)
        {
            numberOfCodons = rnaLength / 3;
            beginIndex = 0;
            richTextBox2.AppendText("Total Number Of codons are: ");
            richTextBox2.AppendText(numberOfCodons.ToString());
            richTextBox2.AppendText("\n");
            for (i = 0; i < numberOfCodons; i++)
            {

                endIndex = beginIndex + 3;
                codon = "";
                
                {



//these are the two possible conversions of the C++ code that dont work at all for me******

    // codon.AppendText(RNA.Substring(beginIndex, endIndex - beginIndex));
                    codon=(RNA.Substring(beginIndex, endIndex - beginIndex));

                }
                for (k = 0; k < 64; k++)
                {
                    if (codon == codons[k])
                    {


//supposed to print out all the coresponding amino acids from the array and it will only print out one amino acid (Lysine)*******
                       
    //protein.AppendText(aminoAcids[k]);
                        protein = (aminoAcids[k]);
                    }

                }
                beginIndex += 3;
            }
            richTextBox2.AppendText(protein);
            richTextBox2.AppendText("\n");
            //protein.clear();   

        }



Why is it doing this and how can I fix it???

Is This A Good Question/Topic? 0
  • +

Replies To: How to append selected array elements to a string for cout like in C++

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: How to append selected array elements to a string for cout like in C++

Posted 13 October 2012 - 06:03 AM

Just a suggestion, read about Dictionary


You can use it like this
Dictionary<string, string> dictionary =
	    new Dictionary<string, string>();

"AAA GGG CCC" can be the Key and "Lysine Glycine Proline" can be the value

This post has been edited by Michael26: 13 October 2012 - 06:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1