号码到土耳其语文本应用程序
我正在尝试转换在文本框中输入的数字。但是我找不到正确的原因,不起作用。您也请看一下。先谢谢您!
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(txtNumber.Text.Length - (txtNumber.Text.Length - j))
是j
,所以:您要将 10 与 j 进行异或吗?
此外,“Sekizmilyon”不是一个词。您需要在中间留一个空格。
(txtNumber.Text.Length - (txtNumber.Text.Length - j))
isj
, so:You're XOR'ing 10 with j?
Also, "Sekizmilyon" is not a word. You need a put a space in between.
看起来您正在尝试使用
^
计算 10 的幂,而您可能指的是Math.Pow
。使用建议的减少aib,您的行:变为:
其他一些建议:
更改
NumberControl
以返回布尔值,以便您可以跳过对的调用ReadNumber
如果输入的数字太大。目前,即使数字超过 7 位,它也会进入ReadNumber
,这会导致数组越界错误以
if (txtSayi.Text.Length != 7)
似乎多余。It looks like you're trying to calculate a power of 10 with
^
when you probably meanMath.Pow
. Using the reduction aib suggested, your line:becomes:
A couple of other suggestions:
Change
NumberControl
to return a bool so you can skip the call toReadNumber
if the entered number is too large. Currently it goes intoReadNumber
even if the number is more than 7 digits, which results in an array out of bounds errorThe block of code starting with
if (txtSayi.Text.Length != 7)
seems redundant.