I need to create a method that takes in a string of numbers - for example, 174709580098747434. It then needs to be formatted as chunks of three and returned in an array - for example, {174, 709, 580, 098,747,434}.
Here is what I have so far. I dont think this is doing the right job. Also it wont be useful if i have a very large number like above.
I am very new to C# and just a beginner!
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string ques = "17470958834";
Console.WriteLine(Chunk(ques));
}
public static string Chunk(string num)
{
// long inInt = Convert.ToInt64(num);
string ans = "";
for (int i = 0; i < num.Length; i += 3)
{
if (i == 2)
{
ans.Insert(2, "-");
}
else if (i == 5)
{
ans.Insert(5, "-");
}
else if (i == 8)
{
ans.Insert(8, "-");
}
else if (i == 11)
{
ans.Insert(11, "-");
}
}
return ans;
}
}
}