号码到土耳其语文本应用程序

发布于 2024-10-02 12:25:14 字数 3237 浏览 4 评论 0原文

我正在尝试转换在文本框中输入的数字。但是我找不到正确的原因,不起作用。您也请看一下。先谢谢您!

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;

namespace NumberToText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void NumberControl()
        {
            if ((txtNumber.Text.Length>7))
            {
                MessageBox.Show("Please enter a smaller number");
            }
        }
        public void ReadNumber()
        {


            try
            {
                int ones, tens, hundreds, thousands, tenthousands, hundredthousands, 

millions;
                int number = Convert.ToInt32(txtNumber.Text);

                int[] array=new int[7];



                for (int j = 0; j < txtNumber.Text.Length; )  
                {

                    array[j] = (number / (10 ^ (txtNumber.Text.Length - 

(txtNumber.Text.Length - j)))) % 10;
                    j += 1;
                }
                if (txtSayi.Text.Length != 7) 
                {
                    for (int i = 6; i >= txtNumber.Text.Length; )
                    {
                        dizi[i] = 0;
                        i-=1;
                    }
                }

                  ones = array[0];
                  tens = array[1];
                  hundreds = array[2];
                  thousands = array[3];
                  tenthousands = array[4];
                  hundredthousands = array[5];
                  millions = array[6];

                //Converting to numbers in TURKISH Text

                string[] a_ones = { "", "Bir", "İki", "Üç", "Dört", "Beş", "Altı", 

"Yedi", "Sekiz", "Dokuz" };
                string[] a_tens = { "", "On", "Yirmi", "Otuz", "Kırk", "Elli", 

"Altmış", "Yetmiş", "Seksen", "Doksan" };
                string[] a_hundreds = { "", "Yüz", "İkiyüz", "Üçyüz", "Dörtyüz", 

"Beşyüz", "Altıyüz", "Yediyüz", "Sekizyüz", "Dokuzyüz" };
                string[] a_thousands = { "", "Bin", "İkibin", "Üçbin", "Dörtbin", 

"Beşbin", "Altıbin", "Yedibin", "Sekizbin", "Dokuzbin" };
                string[] a_tenthousands = { "", "On", "Yirmi", "Otuz", "Kırk", 

"Elli", "Altmış", "Yetmiş", "Seksen", "Doksan" };
                string[] a_hundredthousands = { "", "Yüz", "İkiyüz", "Üçyüz", 

"Dörtyüz", "Beşyüz", "Altıyüz", "Yediyüz", "Sekizyüz", "Dokuzyüz" };
                string[] a_millions = { "", "Birmilyon", "İkimilyon", "Üçmilyon", 

"Dörtmilyon", "Beşmilyon", "Altımilyon", "Yedimilyon", "Sekizmilyon", "Dokuzmilyon" 

};

                lblText.Text = a_millions[millions] + " " + a_hundredthousands

[hundredthousands] + a_tenthousands[tenthousands] + " " + a_thousands[thousands] + "  

" + a_hundreds[hundreds] + " " + a_tens[tens] + " " + a_ones[ones];

            } 
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message.ToString());
            }
        }




        private void btnConvert_Click(object sender, EventArgs e)
        {
            NumberControl();
            ReadNumber();

        }

    }
}

I m Trying to convert a number entered in the text box post.But I can not find the right reasons, does not work.Are you also please have a look.Thank you in advance!

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;

namespace NumberToText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void NumberControl()
        {
            if ((txtNumber.Text.Length>7))
            {
                MessageBox.Show("Please enter a smaller number");
            }
        }
        public void ReadNumber()
        {


            try
            {
                int ones, tens, hundreds, thousands, tenthousands, hundredthousands, 

millions;
                int number = Convert.ToInt32(txtNumber.Text);

                int[] array=new int[7];



                for (int j = 0; j < txtNumber.Text.Length; )  
                {

                    array[j] = (number / (10 ^ (txtNumber.Text.Length - 

(txtNumber.Text.Length - j)))) % 10;
                    j += 1;
                }
                if (txtSayi.Text.Length != 7) 
                {
                    for (int i = 6; i >= txtNumber.Text.Length; )
                    {
                        dizi[i] = 0;
                        i-=1;
                    }
                }

                  ones = array[0];
                  tens = array[1];
                  hundreds = array[2];
                  thousands = array[3];
                  tenthousands = array[4];
                  hundredthousands = array[5];
                  millions = array[6];

                //Converting to numbers in TURKISH Text

                string[] a_ones = { "", "Bir", "İki", "Üç", "Dört", "Beş", "Altı", 

"Yedi", "Sekiz", "Dokuz" };
                string[] a_tens = { "", "On", "Yirmi", "Otuz", "Kırk", "Elli", 

"Altmış", "Yetmiş", "Seksen", "Doksan" };
                string[] a_hundreds = { "", "Yüz", "İkiyüz", "Üçyüz", "Dörtyüz", 

"Beşyüz", "Altıyüz", "Yediyüz", "Sekizyüz", "Dokuzyüz" };
                string[] a_thousands = { "", "Bin", "İkibin", "Üçbin", "Dörtbin", 

"Beşbin", "Altıbin", "Yedibin", "Sekizbin", "Dokuzbin" };
                string[] a_tenthousands = { "", "On", "Yirmi", "Otuz", "Kırk", 

"Elli", "Altmış", "Yetmiş", "Seksen", "Doksan" };
                string[] a_hundredthousands = { "", "Yüz", "İkiyüz", "Üçyüz", 

"Dörtyüz", "Beşyüz", "Altıyüz", "Yediyüz", "Sekizyüz", "Dokuzyüz" };
                string[] a_millions = { "", "Birmilyon", "İkimilyon", "Üçmilyon", 

"Dörtmilyon", "Beşmilyon", "Altımilyon", "Yedimilyon", "Sekizmilyon", "Dokuzmilyon" 

};

                lblText.Text = a_millions[millions] + " " + a_hundredthousands

[hundredthousands] + a_tenthousands[tenthousands] + " " + a_thousands[thousands] + "  

" + a_hundreds[hundreds] + " " + a_tens[tens] + " " + a_ones[ones];

            } 
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message.ToString());
            }
        }




        private void btnConvert_Click(object sender, EventArgs e)
        {
            NumberControl();
            ReadNumber();

        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹梦到西洲 2024-10-09 12:25:14
for (int j = 0; j < txtNumber.Text.Length; )  
{
    array[j] = (number / (10 ^ (txtNumber.Text.Length - (txtNumber.Text.Length - j)))) % 10;
    j += 1;
}

(txtNumber.Text.Length - (txtNumber.Text.Length - j))j,所以:

for (int j = 0; j < txtNumber.Text.Length; j += 1)  
{
    array[j] = (number / (10 ^ j)) % 10;
}

您要将 10 与 j 进行异或吗?

此外,“Sekizmilyon”不是一个词。您需要在中间留一个空格。

for (int j = 0; j < txtNumber.Text.Length; )  
{
    array[j] = (number / (10 ^ (txtNumber.Text.Length - (txtNumber.Text.Length - j)))) % 10;
    j += 1;
}

(txtNumber.Text.Length - (txtNumber.Text.Length - j)) is j, so:

for (int j = 0; j < txtNumber.Text.Length; j += 1)  
{
    array[j] = (number / (10 ^ j)) % 10;
}

You're XOR'ing 10 with j?

Also, "Sekizmilyon" is not a word. You need a put a space in between.

几度春秋 2024-10-09 12:25:14

看起来您正在尝试使用 ^ 计算 10 的幂,而您可能指的是 Math.Pow。使用建议的减少aib,您的行:

array[j] = (number / (10 ^ (txtNumber.Text.Length - (txtNumber.Text.Length - j)))) % 10;

变为:

array[j] = (number / (int)Math.Pow(10, j)) % 10;

其他一些建议:

  1. 更改NumberControl以返回布尔值,以便您可以跳过对的调用ReadNumber 如果输入的数字太大。目前,即使数字超过 7 位,它也会进入 ReadNumber,这会导致数组越界错误

  2. if (txtSayi.Text.Length != 7) 似乎多余。

It looks like you're trying to calculate a power of 10 with ^ when you probably mean Math.Pow. Using the reduction aib suggested, your line:

array[j] = (number / (10 ^ (txtNumber.Text.Length - (txtNumber.Text.Length - j)))) % 10;

becomes:

array[j] = (number / (int)Math.Pow(10, j)) % 10;

A couple of other suggestions:

  1. Change NumberControl to return a bool so you can skip the call to ReadNumber if the entered number is too large. Currently it goes into ReadNumber even if the number is more than 7 digits, which results in an array out of bounds error

  2. The block of code starting with if (txtSayi.Text.Length != 7) seems redundant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文