السلام عليكم
وجدت كود بلغة ال 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;
}
