How to Split Number Into Digit in Windows Store App


In this article I explain how to separate each digit from specified number. For example: "5674" is presented in the from of "5 6 7  4"; in other words, I have separated each digit from the number.

Use the  following procedure to split a number into digits.

Step 1

First of all you have to create a new Windows Store Application.

  • Open Visual Studio 2012
  • "File" -> "New" -> "Project..."
  • Choose "Template" -> "Visual C#" -> "Window Store app"
  • Choose "Blank App (XAML)" then rename the application


Step 2

Write the following XAML code in "Mainpage.Xaml" (that is available in Solution Explorer):










    <Grid Background="Red">


            <RowDefinition Height="131*"/>

            <RowDefinition Height="44*"/>

            <RowDefinition Height="41*"/>

            <RowDefinition Height="41*"/>

            <RowDefinition Height="36*"/>

            <RowDefinition Height="374*"/>

            <RowDefinition Height="101*"/>



            <ColumnDefinition Width="164*"/>

            <ColumnDefinition Width="128*"/>

            <ColumnDefinition Width="391*"/>


        <TextBlock Text="Split Number into Digit " FontSize="20" FontWeight="ExtraBold" FontFamily="Arial" Grid.Column="1" Grid.Row="1" ></TextBlock>

        <TextBlock Text="Enter Number:" FontSize="20" FontWeight="ExtraBold" FontFamily="Arial" Grid.Column="1" Grid.Row="2" ></TextBlock>

        <TextBox x:Name="textbox1" Grid.Column="2" Grid.Row="2" Width="200" Height="32" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBox>

        <Button x:Name="button1" Content="click" Grid.Column="2" Grid.Row="3" Width="104" Click="button1_Click" Background="Yellow" Foreground="Black" Height="38" Margin="0,3,0,0" VerticalAlignment="Top" />

        <TextBlock x:Name="text1" FontSize="20" FontWeight="ExtraBold" FontFamily="Arial" Grid.Column="2" Grid.Row="4" Width="394" HorizontalAlignment="Left"  ></TextBlock>





Step 3

Now write the following C# code for the button within "Mainpage.Xaml.cs".

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using Windows.Foundation;

using Windows.Foundation.Collections;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Controls.Primitives;

using Windows.UI.Xaml.Data;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

using Windows.UI.Xaml.Navigation;


namespace digit_app


    public sealed partial class MainPage : Page


        public MainPage()




        protected override void OnNavigatedTo(NavigationEventArgs e)



        private void button1_Click(object sender, RoutedEventArgs e)


            int num = 0, temp;

            int factor = 1;       

            num = Convert.ToInt32(textbox1.Text);

            temp = num;

            while (temp  > 0)


                temp = temp / 10;             

                factor = factor * 10;               


            while (factor > 1)


                factor = factor / 10;

                text1.Text += (num / factor) + " ";

                num = num % factor;






Step 4

Now run your app.