الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تحويل الارقام لكلمات

مغلق
بدأه aaaaaForum في 16 أبريل 2006 · 14 رد · 1,518 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

وجدت كود بلغة ال c للتحويل من الارقام ال الكلمات.

عندما حولته لل #C واجهتني بعض المشاكل.

private void Button1_Click(object sender, System.EventArgs e)

{

int nValue=1235;

string [] strOnes=new string[10] {"\0","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "};

string [] strTyes=new string[8] { "Twenty ","Thirty ","Forty ","Fifty ","Sixty ", "Seventy ","Eighty ","Ninety "};

string [] strTeens=new string[10] {"Ten ","Eleven ","Twelve ","Thirteen ","Fourteen ", "Fifteen ","Sixteen ","Seventeen ","Eighteen ","Nineteen "};

string [] strIons=new string[] {"Billion ","Million ","Thousand ","\0"};

string strInput;

//string strOutput={0};

string strOutput;

int nCurPos=0,nOne, nTen, nHundred;

if(nValue==0)

//return "Zero";

TextBox1.Text="Zero";

// Convert to 12/ Digit, Zero filled string.

// This makes processing somewhat easier.

//sprintf(strInput,"%012u",nValue);

// Until ALL 12 digits have been exhausted

while(nCurPos <= 9)

{

// Get the numeric value of three digits

nHundred = strInput[nCurPos++] - 48;

nTen = strInput[nCurPos++] - 48;

nOne = strInput[nCurPos++] - 48;

// Are all ZEROES? Then.. SKIP

if (nHundred==0 && nTen==0 && nOne==0)

continue; // Nothing to process... :(

// Is Hundred value there?

if(nHundred==0)

{

// Yes! Hold ONES value and append 'Hundred '

strOutput=strOutput+strOnes[nHundred];

strOutput=strOutput+"Hundred ";

}

// Special case for TEENS value (10 to 19)

if(nTen==1) // If in teens range

//strcat(strOutput,strTeens[nOne]);

strOutput=strOutput+strTeens[nOne];

else

{

// Test if TEN value is there..

// Note that we come here when TEN != 1 (That is, 0..9, 20..99)

// Following tests for second range (20..99) and adds 'Ty'es value.

if(nTen==0)

//strcat(strOutput,strTyes[nTen-2]);

strOutput=strOutput+strTyes[nTen-2];

// Add up the ONE value.

//strcat(strOutput,strOnes[nOne]);

strOutput=strOutput+strOnes[nOne];

}

// Add this ION.

//strcat(strOutput,strIons[(nCurPos-1)/3]);

strOutput=strOutput+strIons[(nCurPos-1)/3];

/* NOTE: There are cases where NULL value is appended implicity

instead of checking with ZERO. Please see the string constants

defined in header file. */

}

// Simple Integrity check

//ASSERT(strlen(strOutput)<=240);

ASSERT(strOutput.Length<=240);

//strOutput[strlen(strOutput)-1]=0; // Put null at last space

strOutput[strOutput.Length-1]='0'; // Put null at last space

// Implicit conversion from char[] to CString

//return strOutput;

TextBox1.Text=strOutput;

}

#2

هل من الممكن أن تعمل تحرير للمقالة وتضع الكود داخل CODE Tage

Name : Ahmed H. Alawady

Web Site : Alawady.info

Email : alawady_ahmed@hotmail.com

Tel : +2 012 345 6808

#3

تفضل اخي

private void Button1_Click(object sender, System.EventArgs e)
{
int nValue=1235;

string [] strOnes=new string[10] {"\0","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "};
string [] strTyes=new string[8] { "Twenty ","Thirty ","Forty ","Fifty ","Sixty ", "Seventy ","Eighty ","Ninety "};
string [] strTeens=new string[10] {"Ten ","Eleven ","Twelve ","Thirteen ","Fourteen ", "Fifteen ","Sixteen ","Seventeen ","Eighteen ","Nineteen "};
string [] strIons=new string[] {"Billion ","Million ","Thousand ","\0"};



string strInput;
//string strOutput={0};
string strOutput;

int nCurPos=0,nOne, nTen, nHundred;

if(nValue==0)
//return "Zero";
TextBox1.Text="Zero";

// Convert to 12/ Digit, Zero filled string.
// This makes processing somewhat easier.
//sprintf(strInput,"%012u",nValue);

// Until ALL 12 digits have been exhausted
while(nCurPos <= 9)
{

// Get the numeric value of three digits
nHundred = strInput[nCurPos++] - 48;
nTen = strInput[nCurPos++] - 48;
nOne = strInput[nCurPos++] - 48;

// Are all ZEROES? Then.. SKIP
if (nHundred==0 && nTen==0 && nOne==0) 
continue; // Nothing to process... 


// Is Hundred value there?
if(nHundred==0)
{
// Yes! Hold ONES value and append 'Hundred '
strOutput=strOutput+strOnes[nHundred];
strOutput=strOutput+"Hundred "; 
}

// Special case for TEENS value (10 to 19)
if(nTen==1) // If in teens range
//strcat(strOutput,strTeens[nOne]);
strOutput=strOutput+strTeens[nOne];
else
{
// Test if TEN value is there.. 
// Note that we come here when TEN != 1 (That is, 0..9, 20..99)
// Following tests for second range (20..99) and adds 'Ty'es value.
if(nTen==0)
//strcat(strOutput,strTyes[nTen-2]);
strOutput=strOutput+strTyes[nTen-2];

// Add up the ONE value.
//strcat(strOutput,strOnes[nOne]);
strOutput=strOutput+strOnes[nOne];
}

// Add this ION.
//strcat(strOutput,strIons[(nCurPos-1)/3]);
strOutput=strOutput+strIons[(nCurPos-1)/3];

/* NOTE: There are cases where NULL value is appended implicity
instead of checking with ZERO. Please see the string constants
defined in header file. */
}

// Simple Integrity check
//ASSERT(strlen(strOutput)<=240);
ASSERT(strOutput.Length<=240);

//strOutput[strlen(strOutput)-1]=0; // Put null at last space
strOutput[strOutput.Length-1]='0'; // Put null at last space

// Implicit conversion from char[] to CString
//return strOutput;
TextBox1.Text=strOutput;


}
#4

عفوا حدث خطا في ارفاق الملف

هذه محاولة اخرى

ConvertNumberToWords.zip

#6

شكرا اخى

ولكني استعملت هذا الموقع وغيره من قبل. كما ان استعملت برامج للترجمة.

ولكن هذا لم يفدني

#9

up

#11

مشكور اخ devil_d

لدي هذا الكود من قبل ولكني لم انجح بتحويله لل C#.

بالمرفقات موجود كود اخر وباللغه العربية.

NumbertoString.rar

#13

عزيزي هذا sql function يقوم بالتحويل من ارقام الى كلمات بسيط وسهل

CREATE FUNCTION NumToWords

(@num numeric)

RETURNS varchar(1000)

AS

BEGIN

DECLARE @cNum varchar(20)

SET @cNum = @num

DECLARE @len int

SET @len = LEN(@Num)

DECLARE @place int

SET @place = 0

DECLARE @digit varchar(1), @tens varchar(2)

DECLARE @res varchar(1000)

SET @res = ''

DECLARE @tblNum TABLE

(Num int, NumStr varchar(20))

INSERT INTO @tblNum

SELECT 1, ' ONE' UNION SELECT 2, ' TWO' UNION

SELECT 3, ' THREE' UNION SELECT 4, ' FOUR' UNION

SELECT 5, ' FIVE' UNION SELECT 6, ' SIX' UNION

SELECT 7, ' SEVEN' UNION SELECT 8, ' EIGHT' UNION

SELECT 9, ' NINE' UNION SELECT 10, ' TEN' UNION

SELECT 11, ' ELEVEN' UNION SELECT 12, ' TWELVE' UNION

SELECT 13, ' THIRTEEN' UNION SELECT 14, ' FOURTEEN' UNION

SELECT 15, ' FIFTEEN' UNION SELECT 16, ' SIXTEEN' UNION

SELECT 17, ' SEVENTEEN' UNION SELECT 18, ' EIGHTEEN' UNION

SELECT 19, ' NINETEEN' UNION

SELECT 20, ' TWENTY' UNION SELECT 30, ' THIRTY' UNION

SELECT 40, ' FOURTY' UNION SELECT 50, ' FIFTY' UNION

SELECT 60, ' SIXTY' UNION SELECT 70, ' SEVENTY' UNION

SELECT 80, ' EIGHTY' UNION SELECT 90, ' NINETY'

DECLARE @hundred varchar(200)

SET @hundred = ''

DECLARE @nStr varchar(20)

WHILE @place < @len

BEGIN

SET @tens = ''

SET @nStr = NULL

SET @digit = SUBSTRING(@cNum, @len - @place, 1)

--SET @digit = SUBSTRING(@Num, @len - @p

-- lace, 1)

IF @place % 3 = 0-- one's place

BEGIN

-- Check ten's place

SET @tens = SUBSTRING(@cNum, @len - @place - 1, 2)

--SET @tens = SUBSTRING(@Num, @len - @pl

-- ace - 1, 2)

SELECT @nStr = NumStr FROM @tblNum WHERE Num = @tens

IF @nStr IS NOT NULL

SELECT @hundred = @hundred + @nStr, @place = @place + 1

ELSE

BEGIN

SELECT @nStr = NumStr FROM @tblNum WHERE Num = @digit

SET @hundred = ISNULL(@nStr, '') + @hundred

END

END

ELSE IF @place % 3 = 1-- Ten's place

BEGIN

SELECT @nStr = NumStr FROM @tblNum WHERE Num = @digit * 10--POWER(10, @place % 3)

SET @hundred = ISNULL(@nStr, '') + @hundred

END

IF @place % 3 = 2-- '000 place

BEGIN

SELECT @nStr = NumStr FROM @tblNum WHERE Num = @digit

IF @nStr IS NOT NULL

SET @hundred = @nStr + ' HUNDRED' + @hundred

--print '000 place'

IF LEN(@hundred) > 0

SET @res = @hundred +

CASE @place / 3

WHEN 0 THEN ''

WHEN 1 THEN ' THOUSAND'

WHEN 2 THEN ' MILLION'

WHEN 3 THEN ' BILLION'

WHEN 4 THEN ' TRILLION'

WHEN 5 THEN ' QUADRILLION'

WHEN 6 THEN ' QUINTILLION'

END + @res

SET @hundred = ''

END

SET @place = @place + 1

END

RETURN @res

END

#14

هذا ما يسمى بالعربي: تفقيط

يوجد مواضيع كثير حوله في مختلف الأقسام

قطرة الماء تـثـقب الحجر.. لا بالعنف. لكن بتكرار المحاولة

at4re.gif

منتديات الفريق العربي للهندسة العكسية 不喜欢的勿入! www.at4re.com

#15

السلام عليكم

مشكور اخ mooad285.

ولكني ابحث عن كود بلغة ال #C.

هذا الموضوع مغلق.

مواضيع مشابهة