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 123 views
123 views asked Aug 28, 2020 by avibootz
1 answer 174 views
1 answer 198 views
1 answer 100 views
1 answer 159 views
1 answer 133 views
...