Hello All,
Here i have one number like 123456. that number i stored in one variable. i want that number should come like 12 34 56(output) through C# code.
Thanks in Advance
Regards
Hareesh
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 12, 2014, 2:30 AM EDT
Rishikesh Kumar SinghRank #1,250 · 1.4K reputationPosted Aug 12, 2014, 3:16 AM EDT
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("Enter a number ");
n = int.Parse(Console.ReadLine());
Console.WriteLine(formatNumber(n.ToString()));
Console.Read();
}
static string formatNumber(string n)
{
int i = 0;
string fn = "";
int Length;
Length = n.Length - 1;
while (Length >= 0)
{
fn = fn + n[i];
if ((i+1) % 2 == 0)
fn = fn + " ";
Length--;
i++;
}
return fn;
}
}
//Mark as accepted answer if it helps you..!!
VulpesRank #55 · 29.2K reputationPosted Aug 12, 2014, 6:23 AM EDT
using System.Text.RegularExpressions;
//...
Hemant SrivastavaRank #581 · 4.2K reputationPosted Aug 12, 2014, 7:41 AM EDT
Here is another way:
class Program
{
public static void Main()
{
int myNumber = 12456;
int numOfDigits = myNumber.ToString().Length -2;
while (numOfDigits > 0)
{
int numPart = myNumber / (int)Math.Pow(10, numOfDigits); // Slicing number
Console.Write(numPart + " ");
myNumber = myNumber % (int)Math.Pow(10, numOfDigits); // Shrinking number
numOfDigits -= 2;
}
Console.Write(myNumber + " "); // For last part of the number
Console.ReadLine();
}
}
Hari B129 reputationPosted Aug 14, 2014, 1:15 AM EDT
i have one excel file i want to read and store in some place. problem is in that excel file there is some tables i will send excel check it once. so read separate table wise and based on the bit 0, bit 1, bit2....bit 7 will read total excel file how to read. this is diffrent from excel look like merging cells in one excel file.
please help me
Thanks in advance
Hareesh