#1,116 – Iterating Through a String Using the foreach Statement

You can iterate through the individual characters in a string using the foreach statement.  The iteration variable is of type char and is set consecutively to each character within the string as the foreach statement executes.

            string secret = "Kint is Keyser Soze";

            StringBuilder sbObfuscate = new StringBuilder();

            foreach (char c in secret)
                sbObfuscate.Append((char)(c + 3));

            Console.WriteLine(sbObfuscate);

1116-001

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #1,116 – Iterating Through a String Using the foreach Statement

  1. Pingback: Dew Drop – June 12, 2014 (#1796) | Morning Dew

Leave a comment