hello i am new beginner ,
please help me to split the integer which is user defined......
for example if user enters :(123456)
then
output should be : 1
2
3
4
5
6
*** without using ArrayList
Thanks.
Loading

Sam HobbsRank #107 · 20.5K reputationPosted Jan 19, 2010, 11:53 AM EST
foreach (char c in s)
Console.WriteLine(c);
theLizardRank #1,079 · 1.8K reputationPosted Jan 19, 2010, 3:20 PM EST
Technically string s is an array of chars and an array list is an array of say, objects which can be an array of chars and arun does not want to use arrays so technically speaking an integer cannot be split as he/she wants without an array of somethings.
I am being funny or silly whichever way you want to look at it. :}
Sam HobbsRank #107 · 20.5K reputationPosted Jan 19, 2010, 6:17 PM EST
So the way I might do it if the data is an integer, not a string, is to divide by successively decreasing powers of ten, then round down of course, then multiply the result by the corresponding power of ten in order to subtract that from the integer so that the next power of ten produces a one-digit result. I hope araun understands that; since this is a class assignment, I won't do the code but I won't complain if someone else does.
theLizardRank #1,079 · 1.8K reputationPosted Jan 19, 2010, 8:27 PM EST
I would have done it in much the same way as you showed, I guess what I was hinting at was (for the benefit of arun) the fact that it is ok to use an array of some sort to achieve a result and telling a student that they cannot use an ArrayList is pretty silly to me. :}
Lalit MRank #1,186 · 1.5K reputationPosted Feb 7, 2010, 6:54 AM EST
----------------------------
using System; using System.Text.RegularExpressions; class Program { static void Main() { // // String containing numbers. // string sentence = "10 cats, 20 dogs, 40 fish and 1 programmer."; // // Get all digit sequence as strings. // string[] digits = Regex.Split(sentence, @"\D+"); // // Now we have each number string. // foreach (string value in digits) { // // Parse the value to get the number. // int number; if (int.TryParse(value, out number)) { Console.WriteLine(value); } } } } for refKirtan PatelRank #292 · 8.6K reputationPosted Feb 7, 2010, 9:41 AM EST
Here is what you want
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Number :");
string Number = Console.ReadLine();
Console.WriteLine("----------Printng Number ----------");
foreach (char c in Number.ToCharArray())
{
Console.WriteLine(c.ToString());
}
Console.ReadKey();
}
}