How to convert number in string to separate int digits in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string s = "9874";
        
        for (int i = 0; i < s.Length; i++) {
            int n = s[i] - 48;
            Console.WriteLine(n);
        }
    }
}



/*
run:

9
8
7
4

*/

 



answered Oct 23, 2020 by avibootz

Related questions

2 answers 173 views
4 answers 330 views
1 answer 116 views
1 answer 137 views
...