• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-3  評論-5  文章-13  trackbacks-0

            在IVR或語音提示中會用到很多播報數值或金額的片段,現提供源代碼以供參考,如下:

            TransNum.h 文件

            #ifndef _TransNum_H_  
            #define _TransNum_H_  
             
            #include "KYLib.h"  
             
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
             
            /* 常量定義 */ 
             
            // 轉換元素項(translate element item)  
            #define TEI_0              0           // 0  
            #define TEI_1              1           // 1  
            #define TEI_2              2           // 2  
            #define TEI_3              3           // 3  
            #define TEI_4              4           // 4  
            #define TEI_5              5           // 5  
            #define TEI_6              6           // 6  
            #define TEI_7              7           // 7  
            #define TEI_8              8           // 8  
            #define TEI_9              9           // 9  
            #define TEI_10            10           // 10  
            #define TEI_20            11           // 20  
            #define TEI_30            12           // 30  
            #define TEI_40            13           // 40  
            #define TEI_50            14           // 50  
            #define TEI_60            15           // 60  
            #define TEI_70            16           // 70  
            #define TEI_80            17           // 80  
            #define TEI_90            18           // 90  
            #define TEI_10_2          19           // 百  
            #define TEI_10_3          20           // 千  
            #define TEI_10_4          21           // 萬  
            #define TEI_10_8          22           // 億  
            #define TEI_Dot           23           // 點  
            #define TEI_Minus         24           // 負  
             
            #define TEI_Count         25           // 元素項個數  
             
            // 擴充轉換元素項(translate element item)  
            #define TEI_Yuan     TEI_Count         // 元  
            #define TEI_Jiao     TEI_Count+1       // 角  
            #define TEI_Fen      TEI_Count+2       // 分  
            #define TEI_End      TEI_Count+3       // 整  
             
            #define TEI_Count1   TEI_End+1         // 擴充后元素項個數  
             
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
             
            /* 公用函數 */ 
             
            // 轉換數字串為元素項列表  
            // 參數:  
            //    APos                 數字串的開始位置, 并返回結尾或非數字串  
            //    AEnd                 數字串的結尾, 若為 NULL 則判斷'\0'結尾符號  
            //    AElements            存放返回元素項列表, 不允許為 NULL  
            //    AMaxSize             AElements 列表的最大尺寸  
            // 返回值:  
            //    > 0                  返回元素項個數  
            //      0                  調用失敗, APos不是['0'..'9', '.', '-']開頭  
            //     -1                  調用失敗, 參數不合法  
            //     -2                  調用失敗, 元素列表的尺寸不足  
            long     NumToElements(char* &APos, const char* AEnd, char* AElements, long AMaxSize);  
             
            // 擴充為金額的元角分元素(注: AElements 的 MaxSize >= ACount + 2)  
            long     ExtractYJFElements(char* AElements, long ACount);  
             
            // 元素列表轉換成自定義字符串(ATEList 項數至少為 TEI_Count)  
            KYString ElementsToCustom(const KYString* ATEList, const char* AElements, long ACount);  
             
            // 元素列表轉換成數量讀法字符串  
            KYString ElementsToQuantity(const char* AElements, long ACount);  
             
            // 元素列表轉換成大寫金額字符串  
            KYString ElementsToMoney(const char* AElements, long ACount);  
             
            #endif 
            #ifndef _TransNum_H_
            #define _TransNum_H_

            #include "KYLib.h"

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            /* 常量定義 */

            // 轉換元素項(translate element item)
            #define TEI_0              0           // 0
            #define TEI_1              1           // 1
            #define TEI_2              2           // 2
            #define TEI_3              3           // 3
            #define TEI_4              4           // 4
            #define TEI_5              5           // 5
            #define TEI_6              6           // 6
            #define TEI_7              7           // 7
            #define TEI_8              8           // 8
            #define TEI_9              9           // 9
            #define TEI_10            10           // 10
            #define TEI_20            11           // 20
            #define TEI_30            12           // 30
            #define TEI_40            13           // 40
            #define TEI_50            14           // 50
            #define TEI_60            15           // 60
            #define TEI_70            16           // 70
            #define TEI_80            17           // 80
            #define TEI_90            18           // 90
            #define TEI_10_2          19           // 百
            #define TEI_10_3          20           // 千
            #define TEI_10_4          21           // 萬
            #define TEI_10_8          22           // 億
            #define TEI_Dot           23           // 點
            #define TEI_Minus         24           // 負

            #define TEI_Count         25           // 元素項個數

            // 擴充轉換元素項(translate element item)
            #define TEI_Yuan     TEI_Count         // 元
            #define TEI_Jiao     TEI_Count+1       // 角
            #define TEI_Fen      TEI_Count+2       // 分
            #define TEI_End      TEI_Count+3       // 整

            #define TEI_Count1   TEI_End+1         // 擴充后元素項個數

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            /* 公用函數 */

            // 轉換數字串為元素項列表
            // 參數:
            //    APos                 數字串的開始位置, 并返回結尾或非數字串
            //    AEnd                 數字串的結尾, 若為 NULL 則判斷'\0'結尾符號
            //    AElements            存放返回元素項列表, 不允許為 NULL
            //    AMaxSize             AElements 列表的最大尺寸
            // 返回值:
            //    > 0                  返回元素項個數
            //      0                  調用失敗, APos不是['0'..'9', '.', '-']開頭
            //     -1                  調用失敗, 參數不合法
            //     -2                  調用失敗, 元素列表的尺寸不足
            long     NumToElements(char* &APos, const char* AEnd, char* AElements, long AMaxSize);

            // 擴充為金額的元角分元素(注: AElements 的 MaxSize >= ACount + 2)
            long     ExtractYJFElements(char* AElements, long ACount);

            // 元素列表轉換成自定義字符串(ATEList 項數至少為 TEI_Count)
            KYString ElementsToCustom(const KYString* ATEList, const char* AElements, long ACount);

            // 元素列表轉換成數量讀法字符串
            KYString ElementsToQuantity(const char* AElements, long ACount);

            // 元素列表轉換成大寫金額字符串
            KYString ElementsToMoney(const char* AElements, long ACount);

            #endif

            TransNum.cpp 文件

            #include "TransNum.h"  
             
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
             
            /* 常量定義 */ 
             
            // 數量元素列表  
            static const KYString _TE_Quanitys[TEI_Count]  
                                 = {"零",          // 0  
                                    "一",          // 1  
                                    "二",          // 2  
                                    "三",          // 3  
                                    "四",          // 4  
                                    "五",          // 5  
                                    "六",          // 6  
                                    "七",          // 7  
                                    "八",          // 8  
                                    "九",          // 9  
                                    "十",          // 10  
                                    "二十",        // 20  
                                    "三十",        // 30  
                                    "四十",        // 40  
                                    "五十",        // 50  
                                    "六十",        // 60  
                                    "七十",        // 70  
                                    "八十",        // 80  
                                    "九十",        // 90  
                                    "百",          // 百  
                                    "千",          // 千  
                                    "萬",          // 萬  
                                    "億",          // 億  
                                    "點",          // 點  
                                    "負"};         // 負  
             
            // 金額元素列表  
            static const KYString _TE_Moneys[TEI_Count1]  
                                 = {"零",          // 0  
                                    "壹",          // 1  
                                    "貳",          // 2  
                                    "叁",          // 3  
                                    "肆",          // 4  
                                    "伍",          // 5  
                                    "陸",          // 6  
                                    "柒",          // 7  
                                    "捌",          // 8  
                                    "玖",          // 9  
                                    "壹拾",        // 10  
                                    "貳拾",        // 20  
                                    "叁拾",        // 30  
                                    "肆拾",        // 40  
                                    "伍拾",        // 50  
                                    "陸拾",        // 60  
                                    "柒拾",        // 70  
                                    "捌拾",        // 80  
                                    "玖拾",        // 90  
                                    "佰",          // 百  
                                    "仟",          // 千  
                                    "萬",          // 萬  
                                    "億",          // 億  
                                    "點",          // 點  
                                    "負",          // 負  
                                    "元",          // 元  
                                    "角",          // 角  
                                    "分",          // 分  
                                    "整"};         // 整  
             
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
             
            /* 內部函數 */ 
             
            // 掃描數字串并清除左邊的'0'字符  
            static long ScanDigitAndTrimLeft(char* &APos)  
            {  
               // 過濾 '0' 字符  
               char* pBegin = APos;  
               while (*APos == '0')  
                  APos++;  
             
               // 判斷前綴是否為 '0'  
               bool boolPrefix = (pBegin != APos);  
             
               // 繼續掃描  
               pBegin = APos;  
               while ((*APos >= '0') && (*APos <= '9'))  
                  APos++;  
             
               // 計算長度  
               long result = APos - pBegin;  
               if (result == 0)  
                  result = boolPrefix;  
             
               // 返回結果  
               return result;  
            }  
             
            // 掃描數字串并清除左邊的'0'字符  
            static long ScanDigitAndTrimLeft(char* &APos, const char* AEnd)  
            {  
               // 過濾 '0' 字符  
               char* pBegin = APos;  
               while ((APos < AEnd) && (*APos == '0'))  
                  APos++;  
             
               // 判斷前綴是否為 '0'  
               bool boolPrefix = (pBegin != APos);  
             
               // 繼續掃描  
               pBegin = APos;  
               while ((APos < AEnd) && (*APos >= '0') && (*APos <= '9'))  
                  APos++;  
             
               // 計算長度  
               long result = APos - pBegin;  
               if (result == 0)  
                  result = boolPrefix;  
             
               // 返回結果  
               return result;  
            }  
             
            // 掃描數字串并清除右邊的'0'字符  
            static long ScanDigitAndTrimRight(char* &APos)  
            {  
               // 初始化  
               char* pBegin   = APos;  
               char* pLast    = APos;  
             
               // 循環掃描  
               while ((*APos >= '0') && (*APos <= '9'))  
               {  
                  if (*APos != '0')  
                     pLast = APos + 1;  
             
                  APos++;  
               }  
             
               // 返回結果  
               return (pLast - pBegin);  
            }  
             
            // 掃描數字串并清除右邊的'0'字符  
            static long ScanDigitAndTrimRight(char* &APos, const char* AEnd)  
            {  
               // 初始化  
               char* pBegin   = APos;  
               char* pLast    = APos;  
             
               // 循環掃描  
               while ((APos < AEnd) && (*APos >= '0') && (*APos <= '9'))  
               {  
                  if (*APos != '0')  
                     pLast = APos + 1;  
             
                  APos++;  
               }  
             
               // 返回結果  
               return (pLast - pBegin);  
            }  
             
            // 4位數轉換并返回元素項個數  
            static long Digit4ToElements(char* &ADigit, char ANum, char* &AElement,  
                                                 const char* AEnd, bool& AIsOverflow)  
            {  
               // 靜態常量  
               static const char Digit_Unit[4]  = {TEI_0,  TEI_10, TEI_10_2, TEI_10_3};  
               static const char Digit_Ten[10]  = {TEI_0,  TEI_10, TEI_20, TEI_30, TEI_40,  
                                                   TEI_50, TEI_60, TEI_70, TEI_80, TEI_90};  
             
               // 初始化  
               char  charItem;  
               bool  boolZero = false;  
               char* pBegin   = AElement;  
             
               // 循環計算  
               while (ANum > 0)  
               {  
                  // 得到元素項  
                  charItem = *ADigit - '0';  
                  ADigit++;  
                  ANum--;  
             
                  // 判斷是否為 0  
                  if (charItem == 0)  
                     boolZero = true;  
                  else 
                  {  
                     // 添加連接 0  
                     if (boolZero)  
                     {  
                        boolZero    = false;  
                        *AElement++ = TEI_0;  
                     }  
             
                     // 檢查是否溢出  
                     if (AElement >= AEnd)  
                     {  
                        AIsOverflow = true;  
                        break;  
                     }  
                     else if (ANum == 1)  
                        *AElement++ = Digit_Ten[charItem];  
                     else 
                     {  
                        // 保存元素項  
                        *AElement++ = charItem;  
                        if (ANum == 0)  
                           ;  
                        else if (AElement < AEnd)  
                           *AElement++ = Digit_Unit[ANum];  
                        else 
                        {  
                           AIsOverflow = true;  
                           break;  
                        }  
                     }  
                  }  
               }  
             
               // 返回結果  
               return (AElement - pBegin);  
            }  
             
            // 8位數轉換并返回元素項個數  
            static long Digit8ToElements(char* &ADigit, char ANum, char* &AElement,  
                                                 const char* AEnd, bool& AIsOverflow)  
            {  
               if (ANum <= 4)  
                  return Digit4ToElements(ADigit, ANum, AElement, AEnd, AIsOverflow);  
               else 
               {  
                  long result = Digit4ToElements(ADigit, ANum - 4, AElement, AEnd, AIsOverflow);  
                  if (!AIsOverflow)  
                  {  
                     // 添加單位(萬)  
                     if (result == 0)  
                        ;  
                     else if (AElement < AEnd)  
                     {  
                        *AElement++ = TEI_10_4;  
                        result++;  
                     }  
                     else 
                        AIsOverflow = true;  
             
                     // 判斷是否溢出  
                     if (!AIsOverflow)  
                        result += Digit4ToElements(ADigit, 4, AElement, AEnd, AIsOverflow);  
                  }  
             
                  return result;  
               }  
            }  
             
            // 多位數轉換并返回元素項個數  
            static long DigitsToElements(char* &ADigit, long ANum, char* &AElement,  
                                                 const char* AEnd, bool& AIsOverflow)  
            {  
               if (ANum <= 8)  
                  return Digit8ToElements(ADigit, (char)ANum, AElement, AEnd, AIsOverflow);  
               else 
               {  
                  // 初始化  
                  char charHead  = ANum & 0x07;  
                  long intCycle  = ANum >> 3;  
             
                  // 判斷是否 8 位對齊  
                  if (charHead == 0)  
                  {  
                     charHead = 8;  
                     intCycle--;  
                  }  
             
                  // 最高幾位  
                  long intNo;  
                  long intSub = Digit8ToElements(ADigit, charHead, AElement, AEnd, AIsOverflow);  
                  long result = intSub;  
             
                  // 循環處理  
                  while (!AIsOverflow && (intCycle > 0))  
                  {  
                     // 添加單位(億)  
                     if (intSub == 0)  
                        ;  
                     else if (AElement <= AEnd - intCycle)  
                        for (intNo = 0; intNo < intCycle; intNo++)  
                        {  
                           *AElement++ = TEI_10_8;  
                           result++;  
                        }  
                     else 
                        AIsOverflow = true;  
             
                     // 判斷是否溢出  
                     if (!AIsOverflow)  
                     {  
                        intSub  = Digit8ToElements(ADigit, 8, AElement, AEnd, AIsOverflow);  
                        result += intSub;  
                        intCycle--;  
                     }  
                  }  
             
                  // 返回結果  
                  return result;  
               }  
            }  
             
            // 小數點之后的數字轉換并返回元素項個數  
            static long DecimalToElements(char* ADecimal, long ANum, char* &AElement,  
                                                   const char* AEnd, bool& AIsOverflow)  
            {  
               if (AElement <= AEnd - ANum)  
               {  
                  // 循環轉換  
                  for (long intNo = 0; intNo < ANum; intNo++, ADecimal++, AElement++)  
                     *AElement = *ADecimal - '0';  
             
                  // 返回結果  
                  return ANum;  
               }  
               else 
               {  
                  AIsOverflow = true;  
                  return 0;  
               }  
            }  
             
            // 拷貝字符串  
            static void CopyString(char* &ADest, const KYString& AStr)  
            {  
               long intLen = AStr.Length();  
               if (intLen > 0)  
               {  
                  memcpy(ADest, (char*)AStr, intLen);  
                  ADest += intLen;  
               }  
            }  
             
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
             
            /* 公用函數 */ 
             
            // 轉換數字串為元素項列表  
            // 參數:  
            //    APos                 數字串的開始位置, 并返回結尾或非數字串  
            //    AEnd                 數字串的結尾, 若為 NULL 則判斷'\0'結尾符號  
            //    AElements            存放返回元素項列表, 不允許為 NULL  
            //    AMaxSize             AElements 列表的最大尺寸  
            // 返回值:  
            //    > 0                  返回元素項個數  
            //      0                  調用失敗, APos不是['0'..'9', '.', '-']開頭  
            //     -1                  調用失敗, 參數不合法  
            //     -2                  調用失敗, 元素列表的尺寸不足  
            long NumToElements(char* &APos, const char* AEnd, char* AElements, long AMaxSize)  
            {  
               // 檢查參數是否非法  
               if ((APos == NULL) || (AElements == NULL) || (AMaxSize <= 0))  
                  return -1;  
               else if (((*APos < '0') || (*APos > '9')) && (*APos != '.') && (*APos != '-'))  
                  return 0;  
             
               // 初始化  
               long  result         = 0;  
               bool  boolOverflow   = false;  
               char* pElementEnd    = AElements + AMaxSize;  
               long  intLeft        = 0;  
               long  intRight       = 0;  
               char* pLeft          = NULL;  
               char* pRight         = NULL;  
             
               // 負號  
               if (*APos == '-')  
               {  
                  *AElements++ = TEI_Minus;  
                  result++;  
                  APos++;  
               }  
             
               // 判斷是否以'\0'字符結尾  
               if (AEnd == NULL)  
               {  
                  // 掃描左邊數字串  
                  intLeft = ScanDigitAndTrimLeft(APos);  
                  if (intLeft > 0)  
                  {  
                     pLeft    = APos - intLeft;  
                     intLeft  = DigitsToElements(pLeft, intLeft, AElements,  
                                                 pElementEnd, boolOverflow);  
                     result  += intLeft;  
                  }  
             
                  // 檢查是否溢出, 并判斷是否存在小數點  
                  if (boolOverflow)  
                     result = -2;  
                  else if (*APos == '.')  
                  {  
                     APos++;  
                     pRight   = APos;  
                     intRight = ScanDigitAndTrimRight(APos);  
                     if (intRight > 0)  
                     {  
                        // 判斷是否需要添加 0  
                        if (intLeft == 0)  
                        {  
                           *AElements++ = TEI_0;  
                           result++;  
                        }  
             
                        // 檢查元素列表容量  
                        if (AElements < pElementEnd + intRight)  
                        {  
                           *AElements++ = TEI_Dot;  
                           result++;  
                           result      += DecimalToElements(pRight, intRight, AElements,  
                                                            pElementEnd, boolOverflow);  
                        }  
                        else 
                           result = -2;  
                     }  
                     else if (intLeft == 0)  
                        result = 0;  
                  }  
                  else if (intLeft == 0)  
                     result = 0;  
               }  
               else 
               {  
                  // 掃描左邊數字串  
                  intLeft = ScanDigitAndTrimLeft(APos, AEnd);  
                  if (intLeft > 0)  
                  {  
                     pLeft    = APos - intLeft;  
                     intLeft  = DigitsToElements(pLeft, intLeft, AElements,  
                                                 pElementEnd, boolOverflow);  
                     result  += intLeft;  
                  }  
             
                  // 檢查是否溢出, 并判斷是否存在小數點  
                  if (boolOverflow)  
                     result = -2;  
                  else if ((APos < AEnd) && (*APos == '.'))  
                  {  
                     APos++;  
                     pRight   = APos;  
                     intRight = ScanDigitAndTrimRight(APos, AEnd);  
                     if (intRight > 0)  
                     {  
                        // 判斷是否需要添加 0  
                        if (intLeft == 0)  
                        {  
                           *AElements++ = TEI_0;  
                           result++;  
                        }  
             
                        // 檢查元素列表容量  
                        if (AElements < pElementEnd + intRight)  
                        {  
                           *AElements++ = TEI_Dot;  
                           result++;  
                           result      += DecimalToElements(pRight, intRight, AElements,  
                                                            pElementEnd, boolOverflow);  
                        }  
                        else 
                           result = -2;  
                     }  
                     else if (intLeft == 0)  
                        result = 0;  
                  }  
                  else if (intLeft == 0)  
                     result = 0;  
               }  
             
               // 返回結果  
               return result;  
            }  
             
            // 擴充為金額的元角分元素(注: AElements 的 MaxSize >= ACount + 2)  
            long ExtractYJFElements(char* AElements, long ACount)  
            {  
               // 查找小數點  
               long intDot = -1;  
               for (long intNo = 0; intNo < ACount; intNo++, AElements++)  
                  if (*AElements == TEI_Dot)  
                  {  
                     intDot = intNo;  
                     break;  
                  }  
             
               // 初始化  
               long result   = (intDot >= 0) ? intDot : ACount;  
               bool boolEnd  = true;  
             
               // 添加元  
               *AElements++  = TEI_Yuan;  
               result++;  
             
               // 判斷是否存在小數點  
               if ((intDot >= 0) && (intDot < ACount - 1))  
               {  
                  // 取分值  
                  char charFen = (intDot < ACount - 2) ? AElements[1] : 0;  
             
                  // 檢查角是否非 0  
                  if (*AElements != 0)  
                  {  
                     *AElements++;  
                     *AElements++ = TEI_Jiao;  
                     boolEnd      = false;  
                     result      += 2;  
                  }  
             
                  // 檢查分是否非 0  
                  if (charFen != 0)  
                  {  
                     *AElements++ = charFen;  
                     *AElements   = TEI_Fen;  
                     boolEnd      = false;  
                     result      += 2;  
                  }  
               }  
             
               // 判斷是否需要添加  
               if (boolEnd)  
               {  
                  *AElements  = TEI_End;  
                  result++;  
               }  
             
               // 返回結果  
               return result;  
            }  
             
            // 元素列表轉換成自定義字符串(ATEList 項數至少為 TEI_Count)  
            KYString ElementsToCustom(const KYString* ATEList, const char* AElements, long ACount)  
            {  
               // 初始化  
               KYString result;  
             
               // 檢查參數  
               if ((ATEList != NULL) && (AElements != NULL) && (ACount > 0))  
               {  
                  // 初始化  
                  long  intNo;  
                  long  intSize  = 0;  
                  char* pElement = (char*)AElements;  
                  char* pPos;  
             
                  // 計算尺寸  
                  for (intNo = 0; intNo < ACount; intNo++, pElement++)  
                     intSize += ATEList[*pElement].Length();  
             
                  // 分配內存并拷貝數據  
                  result.SetLength(intSize);  
                  pPos     = (char*)result;  
                  pElement = (char*)AElements;  
                  for (intNo = 0; intNo < ACount; intNo++, pElement++)  
                     CopyString(pPos, ATEList[*pElement]);  
               }  
             
               // 返回結果  
               return result;  
            }  
             
            // 元素列表轉換成數量讀法字符串  
            KYString ElementsToQuantity(const char* AElements, long ACount)  
            {  
               return ElementsToCustom(_TE_Quanitys, AElements, ACount);  
            }  
             
            // 元素列表轉換成大寫金額字符串  
            KYString ElementsToMoney(const char* AElements, long ACount)  
            {  
               return ElementsToCustom(_TE_Moneys, AElements, ACount);  

            #include "TransNum.h"

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            /* 常量定義 */

            // 數量元素列表
            static const KYString _TE_Quanitys[TEI_Count]
                                 = {"零",          // 0
                                    "一",          // 1
                                    "二",          // 2
                                    "三",          // 3
                                    "四",          // 4
                                    "五",          // 5
                                    "六",          // 6
                                    "七",          // 7
                                    "八",          // 8
                                    "九",          // 9
                                    "十",          // 10
                                    "二十",        // 20
                                    "三十",        // 30
                                    "四十",        // 40
                                    "五十",        // 50
                                    "六十",        // 60
                                    "七十",        // 70
                                    "八十",        // 80
                                    "九十",        // 90
                                    "百",          // 百
                                    "千",          // 千
                                    "萬",          // 萬
                                    "億",          // 億
                                    "點",          // 點
                                    "負"};         // 負

            // 金額元素列表
            static const KYString _TE_Moneys[TEI_Count1]
                                 = {"零",          // 0
                                    "壹",          // 1
                                    "貳",          // 2
                                    "叁",          // 3
                                    "肆",          // 4
                                    "伍",          // 5
                                    "陸",          // 6
                                    "柒",          // 7
                                    "捌",          // 8
                                    "玖",          // 9
                                    "壹拾",        // 10
                                    "貳拾",        // 20
                                    "叁拾",        // 30
                                    "肆拾",        // 40
                                    "伍拾",        // 50
                                    "陸拾",        // 60
                                    "柒拾",        // 70
                                    "捌拾",        // 80
                                    "玖拾",        // 90
                                    "佰",          // 百
                                    "仟",          // 千
                                    "萬",          // 萬
                                    "億",          // 億
                                    "點",          // 點
                                    "負",          // 負
                                    "元",          // 元
                                    "角",          // 角
                                    "分",          // 分
                                    "整"};         // 整

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            /* 內部函數 */

            // 掃描數字串并清除左邊的'0'字符
            static long ScanDigitAndTrimLeft(char* &APos)
            {
               // 過濾 '0' 字符
               char* pBegin = APos;
               while (*APos == '0')
                  APos++;

               // 判斷前綴是否為 '0'
               bool boolPrefix = (pBegin != APos);

               // 繼續掃描
               pBegin = APos;
               while ((*APos >= '0') && (*APos <= '9'))
                  APos++;

               // 計算長度
               long result = APos - pBegin;
               if (result == 0)
                  result = boolPrefix;

               // 返回結果
               return result;
            }

            // 掃描數字串并清除左邊的'0'字符
            static long ScanDigitAndTrimLeft(char* &APos, const char* AEnd)
            {
               // 過濾 '0' 字符
               char* pBegin = APos;
               while ((APos < AEnd) && (*APos == '0'))
                  APos++;

               // 判斷前綴是否為 '0'
               bool boolPrefix = (pBegin != APos);

               // 繼續掃描
               pBegin = APos;
               while ((APos < AEnd) && (*APos >= '0') && (*APos <= '9'))
                  APos++;

               // 計算長度
               long result = APos - pBegin;
               if (result == 0)
                  result = boolPrefix;

               // 返回結果
               return result;
            }

            // 掃描數字串并清除右邊的'0'字符
            static long ScanDigitAndTrimRight(char* &APos)
            {
               // 初始化
               char* pBegin   = APos;
               char* pLast    = APos;

               // 循環掃描
               while ((*APos >= '0') && (*APos <= '9'))
               {
                  if (*APos != '0')
                     pLast = APos + 1;

                  APos++;
               }

               // 返回結果
               return (pLast - pBegin);
            }

            // 掃描數字串并清除右邊的'0'字符
            static long ScanDigitAndTrimRight(char* &APos, const char* AEnd)
            {
               // 初始化
               char* pBegin   = APos;
               char* pLast    = APos;

               // 循環掃描
               while ((APos < AEnd) && (*APos >= '0') && (*APos <= '9'))
               {
                  if (*APos != '0')
                     pLast = APos + 1;

                  APos++;
               }

               // 返回結果
               return (pLast - pBegin);
            }

            // 4位數轉換并返回元素項個數
            static long Digit4ToElements(char* &ADigit, char ANum, char* &AElement,
                                                 const char* AEnd, bool& AIsOverflow)
            {
               // 靜態常量
               static const char Digit_Unit[4]  = {TEI_0,  TEI_10, TEI_10_2, TEI_10_3};
               static const char Digit_Ten[10]  = {TEI_0,  TEI_10, TEI_20, TEI_30, TEI_40,
                                                   TEI_50, TEI_60, TEI_70, TEI_80, TEI_90};

               // 初始化
               char  charItem;
               bool  boolZero = false;
               char* pBegin   = AElement;

               // 循環計算
               while (ANum > 0)
               {
                  // 得到元素項
                  charItem = *ADigit - '0';
                  ADigit++;
                  ANum--;

                  // 判斷是否為 0
                  if (charItem == 0)
                     boolZero = true;
                  else
                  {
                     // 添加連接 0
                     if (boolZero)
                     {
                        boolZero    = false;
                        *AElement++ = TEI_0;
                     }

                     // 檢查是否溢出
                     if (AElement >= AEnd)
                     {
                        AIsOverflow = true;
                        break;
                     }
                     else if (ANum == 1)
                        *AElement++ = Digit_Ten[charItem];
                     else
                     {
                        // 保存元素項
                        *AElement++ = charItem;
                        if (ANum == 0)
                           ;
                        else if (AElement < AEnd)
                           *AElement++ = Digit_Unit[ANum];
                        else
                        {
                           AIsOverflow = true;
                           break;
                        }
                     }
                  }
               }

               // 返回結果
               return (AElement - pBegin);
            }

            // 8位數轉換并返回元素項個數
            static long Digit8ToElements(char* &ADigit, char ANum, char* &AElement,
                                                 const char* AEnd, bool& AIsOverflow)
            {
               if (ANum <= 4)
                  return Digit4ToElements(ADigit, ANum, AElement, AEnd, AIsOverflow);
               else
               {
                  long result = Digit4ToElements(ADigit, ANum - 4, AElement, AEnd, AIsOverflow);
                  if (!AIsOverflow)
                  {
                     // 添加單位(萬)
                     if (result == 0)
                        ;
                     else if (AElement < AEnd)
                     {
                        *AElement++ = TEI_10_4;
                        result++;
                     }
                     else
                        AIsOverflow = true;

                     // 判斷是否溢出
                     if (!AIsOverflow)
                        result += Digit4ToElements(ADigit, 4, AElement, AEnd, AIsOverflow);
                  }

                  return result;
               }
            }

            // 多位數轉換并返回元素項個數
            static long DigitsToElements(char* &ADigit, long ANum, char* &AElement,
                                                 const char* AEnd, bool& AIsOverflow)
            {
               if (ANum <= 8)
                  return Digit8ToElements(ADigit, (char)ANum, AElement, AEnd, AIsOverflow);
               else
               {
                  // 初始化
                  char charHead  = ANum & 0x07;
                  long intCycle  = ANum >> 3;

                  // 判斷是否 8 位對齊
                  if (charHead == 0)
                  {
                     charHead = 8;
                     intCycle--;
                  }

                  // 最高幾位
                  long intNo;
                  long intSub = Digit8ToElements(ADigit, charHead, AElement, AEnd, AIsOverflow);
                  long result = intSub;

                  // 循環處理
                  while (!AIsOverflow && (intCycle > 0))
                  {
                     // 添加單位(億)
                     if (intSub == 0)
                        ;
                     else if (AElement <= AEnd - intCycle)
                        for (intNo = 0; intNo < intCycle; intNo++)
                        {
                           *AElement++ = TEI_10_8;
                           result++;
                        }
                     else
                        AIsOverflow = true;

                     // 判斷是否溢出
                     if (!AIsOverflow)
                     {
                        intSub  = Digit8ToElements(ADigit, 8, AElement, AEnd, AIsOverflow);
                        result += intSub;
                        intCycle--;
                     }
                  }

                  // 返回結果
                  return result;
               }
            }

            // 小數點之后的數字轉換并返回元素項個數
            static long DecimalToElements(char* ADecimal, long ANum, char* &AElement,
                                                   const char* AEnd, bool& AIsOverflow)
            {
               if (AElement <= AEnd - ANum)
               {
                  // 循環轉換
                  for (long intNo = 0; intNo < ANum; intNo++, ADecimal++, AElement++)
                     *AElement = *ADecimal - '0';

                  // 返回結果
                  return ANum;
               }
               else
               {
                  AIsOverflow = true;
                  return 0;
               }
            }

            // 拷貝字符串
            static void CopyString(char* &ADest, const KYString& AStr)
            {
               long intLen = AStr.Length();
               if (intLen > 0)
               {
                  memcpy(ADest, (char*)AStr, intLen);
                  ADest += intLen;
               }
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            /* 公用函數 */

            // 轉換數字串為元素項列表
            // 參數:
            //    APos                 數字串的開始位置, 并返回結尾或非數字串
            //    AEnd                 數字串的結尾, 若為 NULL 則判斷'\0'結尾符號
            //    AElements            存放返回元素項列表, 不允許為 NULL
            //    AMaxSize             AElements 列表的最大尺寸
            // 返回值:
            //    > 0                  返回元素項個數
            //      0                  調用失敗, APos不是['0'..'9', '.', '-']開頭
            //     -1                  調用失敗, 參數不合法
            //     -2                  調用失敗, 元素列表的尺寸不足
            long NumToElements(char* &APos, const char* AEnd, char* AElements, long AMaxSize)
            {
               // 檢查參數是否非法
               if ((APos == NULL) || (AElements == NULL) || (AMaxSize <= 0))
                  return -1;
               else if (((*APos < '0') || (*APos > '9')) && (*APos != '.') && (*APos != '-'))
                  return 0;

               // 初始化
               long  result         = 0;
               bool  boolOverflow   = false;
               char* pElementEnd    = AElements + AMaxSize;
               long  intLeft        = 0;
               long  intRight       = 0;
               char* pLeft          = NULL;
               char* pRight         = NULL;

               // 負號
               if (*APos == '-')
               {
                  *AElements++ = TEI_Minus;
                  result++;
                  APos++;
               }

               // 判斷是否以'\0'字符結尾
               if (AEnd == NULL)
               {
                  // 掃描左邊數字串
                  intLeft = ScanDigitAndTrimLeft(APos);
                  if (intLeft > 0)
                  {
                     pLeft    = APos - intLeft;
                     intLeft  = DigitsToElements(pLeft, intLeft, AElements,
                                                 pElementEnd, boolOverflow);
                     result  += intLeft;
                  }

                  // 檢查是否溢出, 并判斷是否存在小數點
                  if (boolOverflow)
                     result = -2;
                  else if (*APos == '.')
                  {
                     APos++;
                     pRight   = APos;
                     intRight = ScanDigitAndTrimRight(APos);
                     if (intRight > 0)
                     {
                        // 判斷是否需要添加 0
                        if (intLeft == 0)
                        {
                           *AElements++ = TEI_0;
                           result++;
                        }

                        // 檢查元素列表容量
                        if (AElements < pElementEnd + intRight)
                        {
                           *AElements++ = TEI_Dot;
                           result++;
                           result      += DecimalToElements(pRight, intRight, AElements,
                                                            pElementEnd, boolOverflow);
                        }
                        else
                           result = -2;
                     }
                     else if (intLeft == 0)
                        result = 0;
                  }
                  else if (intLeft == 0)
                     result = 0;
               }
               else
               {
                  // 掃描左邊數字串
                  intLeft = ScanDigitAndTrimLeft(APos, AEnd);
                  if (intLeft > 0)
                  {
                     pLeft    = APos - intLeft;
                     intLeft  = DigitsToElements(pLeft, intLeft, AElements,
                                                 pElementEnd, boolOverflow);
                     result  += intLeft;
                  }

                  // 檢查是否溢出, 并判斷是否存在小數點
                  if (boolOverflow)
                     result = -2;
                  else if ((APos < AEnd) && (*APos == '.'))
                  {
                     APos++;
                     pRight   = APos;
                     intRight = ScanDigitAndTrimRight(APos, AEnd);
                     if (intRight > 0)
                     {
                        // 判斷是否需要添加 0
                        if (intLeft == 0)
                        {
                           *AElements++ = TEI_0;
                           result++;
                        }

                        // 檢查元素列表容量
                        if (AElements < pElementEnd + intRight)
                        {
                           *AElements++ = TEI_Dot;
                           result++;
                           result      += DecimalToElements(pRight, intRight, AElements,
                                                            pElementEnd, boolOverflow);
                        }
                        else
                           result = -2;
                     }
                     else if (intLeft == 0)
                        result = 0;
                  }
                  else if (intLeft == 0)
                     result = 0;
               }

               // 返回結果
               return result;
            }

            // 擴充為金額的元角分元素(注: AElements 的 MaxSize >= ACount + 2)
            long ExtractYJFElements(char* AElements, long ACount)
            {
               // 查找小數點
               long intDot = -1;
               for (long intNo = 0; intNo < ACount; intNo++, AElements++)
                  if (*AElements == TEI_Dot)
                  {
                     intDot = intNo;
                     break;
                  }

               // 初始化
               long result   = (intDot >= 0) ? intDot : ACount;
               bool boolEnd  = true;

               // 添加元
               *AElements++  = TEI_Yuan;
               result++;

               // 判斷是否存在小數點
               if ((intDot >= 0) && (intDot < ACount - 1))
               {
                  // 取分值
                  char charFen = (intDot < ACount - 2) ? AElements[1] : 0;

                  // 檢查角是否非 0
                  if (*AElements != 0)
                  {
                     *AElements++;
                     *AElements++ = TEI_Jiao;
                     boolEnd      = false;
                     result      += 2;
                  }

                  // 檢查分是否非 0
                  if (charFen != 0)
                  {
                     *AElements++ = charFen;
                     *AElements   = TEI_Fen;
                     boolEnd      = false;
                     result      += 2;
                  }
               }

               // 判斷是否需要添加
               if (boolEnd)
               {
                  *AElements  = TEI_End;
                  result++;
               }

               // 返回結果
               return result;
            }

            // 元素列表轉換成自定義字符串(ATEList 項數至少為 TEI_Count)
            KYString ElementsToCustom(const KYString* ATEList, const char* AElements, long ACount)
            {
               // 初始化
               KYString result;

               // 檢查參數
               if ((ATEList != NULL) && (AElements != NULL) && (ACount > 0))
               {
                  // 初始化
                  long  intNo;
                  long  intSize  = 0;
                  char* pElement = (char*)AElements;
                  char* pPos;

                  // 計算尺寸
                  for (intNo = 0; intNo < ACount; intNo++, pElement++)
                     intSize += ATEList[*pElement].Length();

                  // 分配內存并拷貝數據
                  result.SetLength(intSize);
                  pPos     = (char*)result;
                  pElement = (char*)AElements;
                  for (intNo = 0; intNo < ACount; intNo++, pElement++)
                     CopyString(pPos, ATEList[*pElement]);
               }

               // 返回結果
               return result;
            }

            // 元素列表轉換成數量讀法字符串
            KYString ElementsToQuantity(const char* AElements, long ACount)
            {
               return ElementsToCustom(_TE_Quanitys, AElements, ACount);
            }

            // 元素列表轉換成大寫金額字符串
            KYString ElementsToMoney(const char* AElements, long ACount)
            {
               return ElementsToCustom(_TE_Moneys, AElements, ACount);
            }
             

            測試代碼:

            #include <stdio.h>  
            #include "TransNum.h"  
             
            // 語音文件元素列表  
            static const KYString _TE_Voices[TEI_Count1]  
                           = {"s_0.wav,",          // 0  
                              "s_1.wav,",          // 1  
                              "s_2.wav,",          // 2  
                              "s_3.wav,",          // 3  
                              "s_4.wav,",          // 4  
                              "s_5.wav,",          // 5  
                              "s_6.wav,",          // 6  
                              "s_7.wav,",          // 7  
                              "s_8.wav,",          // 8  
                              "s_9.wav,",          // 9  
                              "s_10.wav,",         // 10  
                              "s_20.wav,",         // 20  
                              "s_30.wav,",         // 30  
                              "s_40.wav,",         // 40  
                              "s_50.wav,",         // 50  
                              "s_60.wav,",         // 60  
                              "s_70.wav,",         // 70  
                              "s_80.wav,",         // 80  
                              "s_90.wav,",         // 90  
                              "s_10_2.wav,",       // 百  
                              "s_10_3.wav,",       // 千  
                              "s_10_4.wav,",       // 萬  
                              "s_10_8.wav,",       // 億  
                              "s_dot.wav,",        // 點  
                              "s_minu.wav,",       // 負  
                              "s_yuan.wav,",       // 元  
                              "s_jiao.wav,",       // 角  
                              "s_fen.wav,",        // 分  
                              "s_end.wav,"};       // 整  
             
            // 輸出轉換結果  
            static void OutputTransResult(TKYDebugFile& AFile, const KYString& AValue)  
            {  
               // 靜態常量  
               static const KYString Log_Line      = "----------------------------------------" 
                                                     "----------------------------------------";  
               static const KYString Fmt_Log1      = "translate {length: %d, value: %s}";  
               static const KYString Fmt_Log2      = "elements  {return: %d, pos: %d, max: %d}";  
               static const KYString Fmt_Log3      = "extractYJF{return: %d}";  
               static const KYString Fmt_Log4      = "quantity  {%s}";  
               static const KYString Fmt_Log5      = "money     {%s}";  
               static const KYString Fmt_Log6      = "voices    {%s}";  
             
               // 初始化  
               KYString strElements;  
               long     intCount, intLen;  
               char*    pElements;  
               char*    pBegin   = (char*)AValue;  
               char*    pPos     = pBegin;  
             
               // 分配元素列表緩沖區  
               intLen = AValue.Length();  
               strElements.SetLength(intLen + intLen);  
               pElements = (char*)strElements;  
             
               // 轉換數字串為元素項列表  
               AFile.WriteFmt(Time(), Fmt_Log1, intLen, pBegin);  
               intCount = NumToElements(pPos, pBegin + intLen, pElements, strElements.Length());  
               AFile.WriteFmt(Time(), Fmt_Log2, intCount, pPos - pBegin + 1, strElements.Length());  
             
               // 若轉換元素表成功則輸出  
               if (intCount > 0)  
               {  
                  // 初始化  
                  KYString strResult;  
             
                  strResult = ElementsToQuantity(pElements, intCount);  
                  AFile.WriteFmt(Time(), Fmt_Log4, (char*)strResult);  
             
                  strResult = ElementsToMoney(pElements, intCount);  
                  AFile.WriteFmt(Time(), Fmt_Log5, (char*)strResult);  
             
                  strResult = ElementsToCustom(_TE_Voices, pElements, intCount);  
                  AFile.WriteFmt(Time(), Fmt_Log6, (char*)strResult);  
             
                  intCount  = ExtractYJFElements(pElements, intCount);  
                  AFile.WriteFmt(Time(), Fmt_Log3, intCount);  
             
                  strResult = ElementsToMoney(pElements, intCount);  
                  AFile.WriteFmt(Time(), Fmt_Log5, (char*)strResult);  
             
                  strResult = ElementsToCustom(_TE_Voices, pElements, intCount);  
                  AFile.WriteFmt(Time(), Fmt_Log6, (char*)strResult);  
               }  
             
               // 結束  
               AFile.Write(Log_Line);  
            }  
             
            // 主函數  
            int main(int argc, char* argv[])  
            {  
               // 靜態常量  
               static const KYString File_Config   = "Translate.ini";  
               static const KYString File_Output   = "Translate.txt";  
               static const KYString Name_Sect     = "config";  
               static const KYString Key_Count     = "count";  
               static const KYString Fmt_Item      = "value_%d";  
             
               // 初始化  
               TKYDebugFile objFile;  
             
               // 打開輸出文件  
               if (objFile.Open(CurrAppFilePath + File_Output, false))  
               {  
                  // 初始化  
                  long     intNo, intCount;  
                  KYString strValue;  
                  TIniFile iniConfig(CurrAppFilePath + File_Config);  
             
                  // 循環輸出  
                  intCount = iniConfig.ReadInteger(Name_Sect, Key_Count, 0);  
                  for (intNo = 0; intNo < intCount; intNo++)  
                  {  
                     strValue = iniConfig.ReadString(Name_Sect, Format(Fmt_Item, intNo), "");  
                     if (strValue.Length() != 0)  
                        OutputTransResult(objFile, strValue);  
                  }  
               }  
               else 
                  printf("output file <%s> opens failure!\n", (char*)File_Output);  
             
               // 返回  
               return 0;  

            #include <stdio.h>
            #include "TransNum.h"

            // 語音文件元素列表
            static const KYString _TE_Voices[TEI_Count1]
                           = {"s_0.wav,",          // 0
                              "s_1.wav,",          // 1
                              "s_2.wav,",          // 2
                              "s_3.wav,",          // 3
                              "s_4.wav,",          // 4
                              "s_5.wav,",          // 5
                              "s_6.wav,",          // 6
                              "s_7.wav,",          // 7
                              "s_8.wav,",          // 8
                              "s_9.wav,",          // 9
                              "s_10.wav,",         // 10
                              "s_20.wav,",         // 20
                              "s_30.wav,",         // 30
                              "s_40.wav,",         // 40
                              "s_50.wav,",         // 50
                              "s_60.wav,",         // 60
                              "s_70.wav,",         // 70
                              "s_80.wav,",         // 80
                              "s_90.wav,",         // 90
                              "s_10_2.wav,",       // 百
                              "s_10_3.wav,",       // 千
                              "s_10_4.wav,",       // 萬
                              "s_10_8.wav,",       // 億
                              "s_dot.wav,",        // 點
                              "s_minu.wav,",       // 負
                              "s_yuan.wav,",       // 元
                              "s_jiao.wav,",       // 角
                              "s_fen.wav,",        // 分
                              "s_end.wav,"};       // 整

            // 輸出轉換結果
            static void OutputTransResult(TKYDebugFile& AFile, const KYString& AValue)
            {
               // 靜態常量
               static const KYString Log_Line      = "----------------------------------------"
                                                     "----------------------------------------";
               static const KYString Fmt_Log1      = "translate {length: %d, value: %s}";
               static const KYString Fmt_Log2      = "elements  {return: %d, pos: %d, max: %d}";
               static const KYString Fmt_Log3      = "extractYJF{return: %d}";
               static const KYString Fmt_Log4      = "quantity  {%s}";
               static const KYString Fmt_Log5      = "money     {%s}";
               static const KYString Fmt_Log6      = "voices    {%s}";

               // 初始化
               KYString strElements;
               long     intCount, intLen;
               char*    pElements;
               char*    pBegin   = (char*)AValue;
               char*    pPos     = pBegin;

               // 分配元素列表緩沖區
               intLen = AValue.Length();
               strElements.SetLength(intLen + intLen);
               pElements = (char*)strElements;

               // 轉換數字串為元素項列表
               AFile.WriteFmt(Time(), Fmt_Log1, intLen, pBegin);
               intCount = NumToElements(pPos, pBegin + intLen, pElements, strElements.Length());
               AFile.WriteFmt(Time(), Fmt_Log2, intCount, pPos - pBegin + 1, strElements.Length());

               // 若轉換元素表成功則輸出
               if (intCount > 0)
               {
                  // 初始化
                  KYString strResult;

                  strResult = ElementsToQuantity(pElements, intCount);
                  AFile.WriteFmt(Time(), Fmt_Log4, (char*)strResult);

                  strResult = ElementsToMoney(pElements, intCount);
                  AFile.WriteFmt(Time(), Fmt_Log5, (char*)strResult);

                  strResult = ElementsToCustom(_TE_Voices, pElements, intCount);
                  AFile.WriteFmt(Time(), Fmt_Log6, (char*)strResult);

                  intCount  = ExtractYJFElements(pElements, intCount);
                  AFile.WriteFmt(Time(), Fmt_Log3, intCount);

                  strResult = ElementsToMoney(pElements, intCount);
                  AFile.WriteFmt(Time(), Fmt_Log5, (char*)strResult);

                  strResult = ElementsToCustom(_TE_Voices, pElements, intCount);
                  AFile.WriteFmt(Time(), Fmt_Log6, (char*)strResult);
               }

               // 結束
               AFile.Write(Log_Line);
            }

            // 主函數
            int main(int argc, char* argv[])
            {
               // 靜態常量
               static const KYString File_Config   = "Translate.ini";
               static const KYString File_Output   = "Translate.txt";
               static const KYString Name_Sect     = "config";
               static const KYString Key_Count     = "count";
               static const KYString Fmt_Item      = "value_%d";

               // 初始化
               TKYDebugFile objFile;

               // 打開輸出文件
               if (objFile.Open(CurrAppFilePath + File_Output, false))
               {
                  // 初始化
                  long     intNo, intCount;
                  KYString strValue;
                  TIniFile iniConfig(CurrAppFilePath + File_Config);

                  // 循環輸出
                  intCount = iniConfig.ReadInteger(Name_Sect, Key_Count, 0);
                  for (intNo = 0; intNo < intCount; intNo++)
                  {
                     strValue = iniConfig.ReadString(Name_Sect, Format(Fmt_Item, intNo), "");
                     if (strValue.Length() != 0)
                        OutputTransResult(objFile, strValue);
                  }
               }
               else
                  printf("output file <%s> opens failure!\n", (char*)File_Output);

               // 返回
               return 0;
            }


            測試例子結果:

            view plaincopy to clipboardprint?
            11:42:14.828 -> translate {length: 5, value: -asdf}  
            11:42:14.828 -> elements  {return: 0, pos: 2, max: 10}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 11, value: -0000000100}  
            11:42:14.828 -> elements  {return: 3, pos: 12, max: 22}  
            11:42:14.828 -> quantity  {負一百}  
            11:42:14.828 -> money     {負壹佰}  
            11:42:14.828 -> voices    {s_minu.wav,s_1.wav,s_10_2.wav,}  
            11:42:14.828 -> extractYJF{return: 5}  
            11:42:14.828 -> money     {負壹佰元整}  
            11:42:14.828 -> voices    {s_minu.wav,s_1.wav,s_10_2.wav,s_yuan.wav,s_end.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 28, value: -0000000000100.1000000000000}  
            11:42:14.828 -> elements  {return: 5, pos: 29, max: 56}  
            11:42:14.828 -> quantity  {負一百點一}  
            11:42:14.828 -> money     {負壹佰點壹}  
            11:42:14.828 -> voices    {s_minu.wav,s_1.wav,s_10_2.wav,s_dot.wav,s_1.wav,}  
            11:42:14.828 -> extractYJF{return: 6}  
            11:42:14.828 -> money     {負壹佰元壹角}  
            11:42:14.828 -> voices    {s_minu.wav,s_1.wav,s_10_2.wav,s_yuan.wav,s_1.wav,s_jiao.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 41, value: 001000000002333330000333333000.0000040000}  
            11:42:14.828 -> elements  {return: 37, pos: 42, max: 82}  
            11:42:14.828 -> quantity  {一千億億億零二百三十三億億三千三百三十萬零三億三千三百三十三萬三千點零零零零零四}  
            11:42:14.828 -> money     {壹仟億億億零貳佰叁拾叁億億叁仟叁佰叁拾萬零叁億叁仟叁佰叁拾叁萬叁仟點零零零零零肆}  
            11:42:14.828 -> voices    {s_1.wav,s_10_3.wav,s_10_8.wav,s_10_8.wav,s_10_8.wav,s_0.wav,s_2.wav,s_10_2.wav,s_30.wav,s_3.wav,s_10_8.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_30.wav,s_10_4.wav,s_0.wav,s_3.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_30.wav,s_3.wav,s_10_4.wav,s_3.wav,s_10_3.wav,s_dot.wav,s_0.wav,s_0.wav,s_0.wav,s_0.wav,s_0.wav,s_4.wav,}  
            11:42:14.828 -> extractYJF{return: 32}  
            11:42:14.828 -> money     {壹仟億億億零貳佰叁拾叁億億叁仟叁佰叁拾萬零叁億叁仟叁佰叁拾叁萬叁仟元整}  
            11:42:14.828 -> voices    {s_1.wav,s_10_3.wav,s_10_8.wav,s_10_8.wav,s_10_8.wav,s_0.wav,s_2.wav,s_10_2.wav,s_30.wav,s_3.wav,s_10_8.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_30.wav,s_10_4.wav,s_0.wav,s_3.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_30.wav,s_3.wav,s_10_4.wav,s_3.wav,s_10_3.wav,s_yuan.wav,s_end.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 42, value: 000000000000002489034000234899345.20920000}  
            11:42:14.828 -> elements  {return: 33, pos: 43, max: 84}  
            11:42:14.828 -> quantity  {二百四十八億億九千零三十四萬零二億三千四百八十九萬九千三百四十五點二零九二}  
            11:42:14.828 -> money     {貳佰肆拾捌億億玖仟零叁拾肆萬零貳億叁仟肆佰捌拾玖萬玖仟叁佰肆拾伍點貳零玖貳}  
            11:42:14.828 -> voices    {s_2.wav,s_10_2.wav,s_40.wav,s_8.wav,s_10_8.wav,s_10_8.wav,s_9.wav,s_10_3.wav,s_0.wav,s_30.wav,s_4.wav,s_10_4.wav,s_0.wav,s_2.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_4.wav,s_10_2.wav,s_80.wav,s_9.wav,s_10_4.wav,s_9.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_40.wav,s_5.wav,s_dot.wav,s_2.wav,s_0.wav,s_9.wav,s_2.wav,}  
            11:42:14.828 -> extractYJF{return: 31}  
            11:42:14.828 -> money     {貳佰肆拾捌億億玖仟零叁拾肆萬零貳億叁仟肆佰捌拾玖萬玖仟叁佰肆拾伍元貳角}  
            11:42:14.828 -> voices    {s_2.wav,s_10_2.wav,s_40.wav,s_8.wav,s_10_8.wav,s_10_8.wav,s_9.wav,s_10_3.wav,s_0.wav,s_30.wav,s_4.wav,s_10_4.wav,s_0.wav,s_2.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_4.wav,s_10_2.wav,s_80.wav,s_9.wav,s_10_4.wav,s_9.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_40.wav,s_5.wav,s_yuan.wav,s_2.wav,s_jiao.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 10, value: 1991.23993}  
            11:42:14.828 -> elements  {return: 12, pos: 11, max: 20}  
            11:42:14.828 -> quantity  {一千九百九十一點二三九九三}  
            11:42:14.828 -> money     {壹仟玖佰玖拾壹點貳叁玖玖叁}  
            11:42:14.828 -> voices    {s_1.wav,s_10_3.wav,s_9.wav,s_10_2.wav,s_90.wav,s_1.wav,s_dot.wav,s_2.wav,s_3.wav,s_9.wav,s_9.wav,s_3.wav,}  
            11:42:14.828 -> extractYJF{return: 11}  
            11:42:14.828 -> money     {壹仟玖佰玖拾壹元貳角叁分}  
            11:42:14.828 -> voices    {s_1.wav,s_10_3.wav,s_9.wav,s_10_2.wav,s_90.wav,s_1.wav,s_yuan.wav,s_2.wav,s_jiao.wav,s_3.wav,s_fen.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 20, value: 90899900002399.01023}  
            11:42:14.828 -> elements  {return: 21, pos: 21, max: 40}  
            11:42:14.828 -> quantity  {九十萬八千九百九十九億二千三百九十九點零一零二三}  
            11:42:14.828 -> money     {玖拾萬捌仟玖佰玖拾玖億貳仟叁佰玖拾玖點零壹零貳叁}  
            11:42:14.828 -> voices    {s_90.wav,s_10_4.wav,s_8.wav,s_10_3.wav,s_9.wav,s_10_2.wav,s_90.wav,s_9.wav,s_10_8.wav,s_2.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_90.wav,s_9.wav,s_dot.wav,s_0.wav,s_1.wav,s_0.wav,s_2.wav,s_3.wav,}  
            11:42:14.828 -> extractYJF{return: 18}  
            11:42:14.828 -> money     {玖拾萬捌仟玖佰玖拾玖億貳仟叁佰玖拾玖元壹分}  
            11:42:14.828 -> voices    {s_90.wav,s_10_4.wav,s_8.wav,s_10_3.wav,s_9.wav,s_10_2.wav,s_90.wav,s_9.wav,s_10_8.wav,s_2.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_90.wav,s_9.wav,s_yuan.wav,s_1.wav,s_fen.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 11, value: 98832212000}  
            11:42:14.828 -> elements  {return: 14, pos: 12, max: 22}  
            11:42:14.828 -> quantity  {九百八十八億三千二百二十一萬二千}  
            11:42:14.828 -> money     {玖佰捌拾捌億叁仟貳佰貳拾壹萬貳仟}  
            11:42:14.828 -> voices    {s_9.wav,s_10_2.wav,s_80.wav,s_8.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_2.wav,s_10_2.wav,s_20.wav,s_1.wav,s_10_4.wav,s_2.wav,s_10_3.wav,}  
            11:42:14.828 -> extractYJF{return: 16}  
            11:42:14.828 -> money     {玖佰捌拾捌億叁仟貳佰貳拾壹萬貳仟元整}  
            11:42:14.828 -> voices    {s_9.wav,s_10_2.wav,s_80.wav,s_8.wav,s_10_8.wav,s_3.wav,s_10_3.wav,s_2.wav,s_10_2.wav,s_20.wav,s_1.wav,s_10_4.wav,s_2.wav,s_10_3.wav,s_yuan.wav,s_end.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 6, value: 100200}  
            11:42:14.828 -> elements  {return: 5, pos: 7, max: 12}  
            11:42:14.828 -> quantity  {十萬零二百}  
            11:42:14.828 -> money     {壹拾萬零貳佰}  
            11:42:14.828 -> voices    {s_10.wav,s_10_4.wav,s_0.wav,s_2.wav,s_10_2.wav,}  
            11:42:14.828 -> extractYJF{return: 7}  
            11:42:14.828 -> money     {壹拾萬零貳佰元整}  
            11:42:14.828 -> voices    {s_10.wav,s_10_4.wav,s_0.wav,s_2.wav,s_10_2.wav,s_yuan.wav,s_end.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 8, value: 23000000}  
            11:42:14.828 -> elements  {return: 5, pos: 9, max: 16}  
            11:42:14.828 -> quantity  {二千三百萬}  
            11:42:14.828 -> money     {貳仟叁佰萬}  
            11:42:14.828 -> voices    {s_2.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_10_4.wav,}  
            11:42:14.828 -> extractYJF{return: 7}  
            11:42:14.828 -> money     {貳仟叁佰萬元整}  
            11:42:14.828 -> voices    {s_2.wav,s_10_3.wav,s_3.wav,s_10_2.wav,s_10_4.wav,s_yuan.wav,s_end.wav,}  
            --------------------------------------------------------------------------------  
            11:42:14.828 -> translate {length: 15, value: 293000000000000}  
            11:42:14.828 -> elements  {return: 6, pos: 16, max: 30}  
            11:42:14.828 -> quantity  {二百九十三萬億}  
            11:42:14.828 -> money     {貳佰玖拾叁萬億}  
            11:42:14.828 -> voices    {s_2.wav,s_10_2.wav,s_90.wav,s_3.wav,s_10_4.wav,s_10_8.wav,}  
            11:42:14.828 -> extractYJF{return: 8}  
            11:42:14.828 -> money     {貳佰玖拾叁萬億元整}  
            11:42:14.828 -> voices    {s_2.wav,s_10_2.wav,s_90.wav,s_3.wav,s_10_4.wav,s_10_8.wav,s_yuan.wav,s_end.wav,}  
            -------------------------------------------------------------------------------- 

             

            本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/kyee/archive/2009/11/07/4783425.aspx

            posted on 2011-05-22 12:51 Kyee Ye 閱讀(252) 評論(0)  編輯 收藏 引用 所屬分類: 源碼
            伊人久久大香线蕉精品| 免费精品国产日韩热久久| 国产精品美女久久久免费| 狠狠色婷婷久久一区二区| 久久精品中文无码资源站| 久久无码专区国产精品发布| 四虎国产精品免费久久久| 日韩亚洲国产综合久久久| 人妻少妇久久中文字幕| 97精品伊人久久大香线蕉| 色偷偷888欧美精品久久久| 亚洲乱码精品久久久久..| 久久伊人影视| 久久精品国产亚洲Aⅴ香蕉| 26uuu久久五月天| 国产精品一久久香蕉国产线看| 久久婷婷五月综合色奶水99啪| 国产激情久久久久久熟女老人| 一级女性全黄久久生活片免费 | 久久精品国产亚洲麻豆| 久久久女人与动物群交毛片| 久久天天躁狠狠躁夜夜网站| 性色欲网站人妻丰满中文久久不卡| 久久免费看黄a级毛片| 午夜精品久久久久成人| 综合久久一区二区三区 | 国产精品免费福利久久| 无码伊人66久久大杳蕉网站谷歌| 久久婷婷国产剧情内射白浆| 久久中文字幕人妻熟av女| 热久久最新网站获取| 精品久久久无码人妻中文字幕| 午夜精品久久久久久中宇| 996久久国产精品线观看| 国产一级持黄大片99久久| 久久人人爽人人爽AV片| 影音先锋女人AV鲁色资源网久久| 亚洲精品无码久久久久sm| 久久国产精品-久久精品| 国产L精品国产亚洲区久久| 国产免费久久久久久无码|