How to loop over string chars in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c# c c++ java";

            foreach (char ch in s)
                Console.WriteLine(ch);
        }
    }
}

/*
run:
 
c
#

c

c
+
+

j
a
v
a
    
*/

 



answered Mar 14, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c# c c++ java";

            for (int i = 0; i < s.Length; i++)
                Console.WriteLine(s[i]);
        }
    }
}

/*
run:
 
c
#

c

c
+
+

j
a
v
a
    
*/

 



answered Mar 14, 2017 by avibootz

Related questions

1 answer 132 views
132 views asked Aug 28, 2020 by avibootz
1 answer 184 views
1 answer 205 views
1 answer 109 views
1 answer 171 views
1 answer 141 views
...