Eder Pardeiro
Eder Pardeiro

Reputation: 51

Put space between digits in C#

I'm need generate a random number an insert a space or comma between digits. This value will be speaked using AWS Polly. Without space, to 6565, she sepeak "six thousand five hundred and sixty five". Part of the code, generating the random number, I already got it, but I don't know how to insert the space between the digits.

Anyone can help me? See bellow:

var withoutSpaces = new Random().Next(10000,100000);
var withSpaces = ????????
return withSpaces;

Wait your answer!

Upvotes: 1

Views: 534

Answers (1)

Mostafa Tarek Yassien
Mostafa Tarek Yassien

Reputation: 532

var withoutSpaces = new Random().Next(10000, 100000);
        string withSpaces = "";
        for (int i = 0; i < withoutSpaces.ToString().Length; i++)
        {
            string test = withoutSpaces.ToString().ElementAt(i) + " ";
            withSpaces += test;
        }
        string WithSpacesFinal = withSpaces.Trim();

This should do it for you

Upvotes: 2

Related Questions