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 274 views
4 answers 514 views
1 answer 202 views
1 answer 224 views
...