-3

I am taking a c# course and this is what it whats me to do:

"Create a string variable named decodedString and set it equal to the contents of the StringTextBox. Create a string variable named encodedString to hold the encoded string and set it equal to an empty string. We will build up the encoded values letter-by-letter in this variable. Use a for() loop to loop through all of the characters in decodedString. Your loop index "i" should start at 0 and increment up to the last character in decodedString."

I'm confused on how I stop the loop at the last character in decodedString. Heres my short bit of code.

        private void EnocodeButton_Click(object sender, EventArgs e)
    {

        String decodeString = StringTextBox.Text;
        String encodeString = "";
        for(int i=0,i== )    //Im not sure what to do here?
    }
  • 1
    The String class has a Length property. https://msdn.microsoft.com/en-us/library/system.string.length(v=vs.110).aspx – Igby Largeman Jan 10 '18 at 21:39
  • If linked duplicate does not provide enough information check out search results for your question https://www.bing.com/search?q=c%23+loop+through+all+of+the+characters+in+string and [edit] post to clarify what you have trouble with. – Alexei Levenkov Jan 10 '18 at 21:43
  • Side note: building strings by repeatedly concatenating stuff is retarded. That's what `System.Text.StringBuilder` is for. – cHao Jan 10 '18 at 22:01

1 Answers1

1

you can get length of the string and use that:

for(int i=0; i<decodedString.Length;i++)
{
  //the ith char -> decodedString[i];
}
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188