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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hari BPosted Aug 14, 2014, 5:15 AM
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
Hemant SrivastavaPosted Aug 12, 2014, 11:41 AM
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();
}
}
VulpesPosted Aug 12, 2014, 10:23 AM
using System.Text.RegularExpressions;
//...
Rishikesh Kumar SinghPosted Aug 12, 2014, 7:16 AM
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..!!
VulpesPosted Aug 12, 2014, 6:30 AM