Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
hello every body i need to convert number c#
like
100 to be 100
101 to be 100 ,0,1
119 to be 100,0,19
123 to be 100,20,3
1001 to be 1000,0,0,1
1020 to be 1000,0,20
1019 to be 100,0,0,19
thanks

this my code
i think i t can be more simple
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 using System.Media;
using System.Threading;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 

 
            Int32 rem1 = 0;//
            Int32 rem2 = 0; ;
            Int32 rem3 = 0;
            Int32 rem4 = 0;
            //string Patiant = System.Convert.ToString(PAT.Text);

            string  Patiant_no = System.Convert.ToString(PAT.Text); ;
            if (Patiant_no.Length == 4)
            {
                rem4 = System.Convert.ToInt32(Patiant_no.Substring(0, 1) + "000");
 
                rem3 = (System.Convert.ToInt32(Patiant_no) - (rem4));
                 rem3 = System.Convert.ToInt32(Patiant_no.Substring(0, 1) + "00");
 
                 rem2 = (System.Convert.ToInt32(Patiant_no) - (rem4) - (rem3));
 
                if (System.Convert.ToString(rem2).Length == 1)
                {
 
                    rem1 = 0;
                    //  rem2 = 0;
                }
                else
                {
 

                    rem1 = 0;
                    if (rem2.ToString().Substring(1, 1) != "0")
                    {
                        if (rem2 <= 19 && rem2 >= 11)
                        {
                            rem1 = 0;
 
                        }
                        else
                        {
                            rem1 = System.Convert.ToInt32(rem2.ToString().Substring(1, 1));
                            rem2 = System.Convert.ToInt32(rem2.ToString().Substring(0, 1) + "0");
 

                        }
 
                    }
 
                }
            }
 
            else if (Patiant_no.Length == 3)
            {
                rem3 = System.Convert.ToInt32(Patiant_no.Substring(0, 1) + "00");
 
                rem2 = (System.Convert.ToInt32(Patiant_no) - (rem3));
 
                if (System.Convert.ToString(rem2).Length == 1)
                {
 
                    rem1 = 0;
                    //  rem2 = 0;
                }
                else
                {
 

                    rem1 = 0;
                    if (rem2.ToString().Substring(1, 1) != "0")
                    {
                        if (rem2 <= 19 && rem2 >= 11)
                        {
                            rem1 = 0;
 
                        }
                        else
                        {
                            rem1 = System.Convert.ToInt32(rem2.ToString().Substring(1, 1));
                            rem2 = System.Convert.ToInt32(rem2.ToString().Substring(0, 1) + "0");
 

                        }
 
                    }
 
                }
 

                SoundPlayer Rem4Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem4 + ".wav");
 
                Rem4Siound.Play();
 
                Thread.Sleep(600);
 

                SoundPlayer Rem3Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem3 + ".wav");
 
                Rem3Siound.Play();
 
                Thread.Sleep(600);
 

                if (rem1 != 0)
                {
 
                    SoundPlayer Rem1Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem1 + ".wav");
 
                    Rem1Siound.Play();
 
                    Thread.Sleep(600);
 
                }
 

 
                {
                    SoundPlayer andSound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\and.wav");
 
                    andSound.Play();
 
                    Thread.Sleep(700);
                }
 
                if (rem2 != 0)
                {
                    SoundPlayer Rem2Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem2 + ".wav");
 
                    Rem2Siound.Play();
 
                    Thread.Sleep(600);
 
                }
 

 
            }
 
            else if (Patiant_no.Length == 2)
            {
                rem3 = 0;
 

                rem2 = System.Convert.ToInt32(Patiant_no);
 
                if (rem2.ToString().Substring(1, 1) != "0")
                {
                    if (rem2 <= 19 && rem2 >= 11)
                    {
 
                        rem1 = 0;
 
                    }
                    else
                    {
                        rem1 = System.Convert.ToInt32(rem2.ToString().Substring(1, 1));
                        rem2 = System.Convert.ToInt32(rem2.ToString().Substring(0, 1) + "0");
 

                    }
 

 
                }
 
                if (rem1 != 0)
                {
                    SoundPlayer Rem1Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem1 + ".wav");
 
                    Rem1Siound.Play();
 
                    Thread.Sleep(700);
 
                    {
                        SoundPlayer andSound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\and.wav");
 
                        andSound.Play();
 
                        Thread.Sleep(700);
                    }
 

                }
 

 

 

 

                if (rem2 != 0)
                {
                    SoundPlayer Rem2Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem2 + ".wav");
 
                    Rem2Siound.Play();
 
                    Thread.Sleep(700);
                }
 
            }
 
            else if (Patiant_no.Length == 1)
            {
                rem3 = 0;
                rem2 = 0;
                rem1 = System.Convert.ToInt32(Patiant_no);
                SoundPlayer Rem1Siound = new SoundPlayer(@"C:\SendWirlessLed\English Sound\" + rem1 + ".wav");
 
                Rem1Siound.Play();
 
                Thread.Sleep(1000);
            }
 

 

 
        }
    }
}
 
can Someone help me
Posted 23-Apr-12 16:47pm
Edited 23-Apr-12 23:15pm
v4
Comments
Walt Fair, Jr. at 23-Apr-12 22:01pm
   
I thought you were separating digits by powers of ten until I saw your 3rd, 6th and 7th examples. If you can you explain the logic behind those, the algorithm should be straight forward and coding will then follow.
asqor at 23-Apr-12 22:12pm
   
i update the question now you can see it
i have a sound system that should read number and i record the wav file like 1.wav to 19 and 20.wav ,30.wav ,40.wav until 100
and 200 300 400 until 1000
Bernhard Hiller at 24-Apr-12 5:45am
   
You can find code for "converting numbers to text/words". Use that and adjust a little for playing your sound files instead of creating the output string.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

JavaScript
function NumBreakDown(nums)
{
        var arr = nums.toString().split('');
        var temp = [];
 
        while(my = arr.shift())
        {
            temp.push(my+'000000'.substr(0, arr.length));
        }
 
        if(temp[temp.length-1] == '0')
        {
            temp.pop();
        }
 
        return temp;
}
 
1763 => ['1000', '700', '60', '3'];
1450 => ['1000', '400', '50'];
  Permalink  
Comments
Maciej Los at 18-Apr-13 6:21am
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

123 to be 100,20,3
1020 to be 1000,0,20
1019 to be 100,0,0,19
 
well, the first one and two lines seems ok, but the last line makes me confused,
do you mean: 1000, 0, 19? or, 1000, 0, 0, 19???
 
maybe, this could be done as below:
 

i == 1,2,3,.... ..
X = pow(10, i) * (n % pow(10,i));
  Permalink  
v2
Comments
asqor at 23-Apr-12 22:02pm
   
1019 to be 1000,0,0,19
Walt Fair, Jr. at 23-Apr-12 22:18pm
   
So what algorithm is used to determine that 1020 -> 1000, 0, 20 while 1019 -> 1000, 0, 0, 19? I don't see any easily inferred pattern there.
asqor at 23-Apr-12 22:24pm
   
please see my code that i update it in the question if any of number rem1 or rem2 or rem3 is 0 no voice will send
Walt Fair, Jr. at 23-Apr-12 22:35pm
   
So, is the algorithm as follows? {1000*a, 100*b, 20*c, d} where a = N div 1000, b = (N - 1000*a) div 100, c = (N - 1000*a - b*100) div 20, d = N mod 20, where div represents an integer division and mod is the modulus operator.
Mohamed_Alex at 23-Apr-12 22:42pm
   
first thanks for you reply
second as i tell you before i need to play the sound like 100 and 23
or 1000 and 20
but im my code i have some problem like 119 it should be 100 and 19
are you got it
Mohamed_Alex at 24-Apr-12 5:43am
   
any updates please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100