• 字符串转换相关


     1    // 七位终端号转十位  例: "EAU001" --> "1410290001"
     2    KYLib::KYString TDevObj::GetTerminalIDByDev(KYString ADevID)
     3    {
     4        KYString result = "";
     5        char szResult[11] = {0};   // 存放10位终端号,需多定义一个字符存放结束符''
     6        char szBuffer[8]  = {0};  
     7        KYString szTmp = "";
     8 
     9        int nIndex = strlen((const char*)ADevID) - 7;
    10        strncpy(szBuffer, (const char*)ADevID + nIndex, 7);
    11        
    12        //
    13        if (szBuffer[0] < 'A'){
    14            szResult[0] = '0';
    15            memcpy(szResult + 1, szBuffer, 1);
    16        }
    17        else{
    18            szTmp = IntToStr(szBuffer[0] - 'A' + 10);
    19            memcpy(szResult, (const char*)szTmp, 2);
    20        }
    21 
    22        //
    23        if (szBuffer[1] < 'A'){
    24            szResult[2] = '0';        // 此位初始化为了结束符, 需赋值'0'
    25            memcpy(szResult + 3, szBuffer + 1, 1);
    26        }
    27        else{
    28            szTmp = IntToStr(szBuffer[1] - 'A' + 10);
    29            memcpy(szResult + 2, (const char*)szTmp, 2);
    30        }
    31 
    32        //
    33        if (szBuffer[2] < 'A'){
    34            szResult[4] = '0';
    35            memcpy(szResult + 5, szBuffer + 2, 1);
    36        }
    37        else if (szBuffer[2] >= 'A' && szBuffer[2] < 'O')
    38        {
    39            szTmp = IntToStr(szBuffer[2] - 'A' + 10);
    40            memcpy(szResult + 4, (const char*)szTmp, 2);
    41        }
    42        else if (szBuffer[2] > 'O')       // 大于字母O的需要减1
    43        {
    44            szTmp = IntToStr(szBuffer[2] - 'A' + 10 -1);
    45            memcpy(szResult + 4, (const char*)szTmp, 2);
    46        }
    47 
    48        memcpy(szResult + 6, szBuffer + 3, 4);
    49 
    50        result = szResult;
    51 
    52        return result;
    53    }
     1 // 十位终端号转七位   例:"1404210001" -->"E4L0001"
     2 string GetConvertCode(char* pTerminalID)
     3 {
     4     char szBuffer[11] = {0};
     5     char szResult[8] = {0};
     6     int nIndex = strlen(pTerminalID) - 10;
     7     strncpy(szBuffer, pTerminalID + nIndex, 10);
     8     szResult[0] = szBuffer[1];
     9     szResult[1] = (szBuffer[2] - 0x30)*10 + (szBuffer[3] - 0x30);
    10     if (szResult[1] >= 10)
    11     {
    12         szResult[1] = szResult[1] - 10 + 'A';
    13     }
    14     else
    15     {
    16         szResult[1] = szResult[1] + '0';
    17     }
    18 
    19     szResult[2] = (szBuffer[4] - 0x30)*10 + (szBuffer[5] - 0x30);
    20     if (szResult[2] >= 24)//屏蔽字母O
    21     {
    22         szResult[2]++;
    23     }
    24     if (szResult[2] >= 10)
    25     {
    26         szResult[2] = szResult[2] - 10 + 'A';
    27     }
    28     else
    29     {
    30         szResult[2] = szResult[2] + '0';
    31     }
    32     memcpy(szResult + 3, szBuffer + 6, 4);
    33     string strRet = szResult;
    34 
    35     return strRet;
    36 }
  • 相关阅读:
    GitHub 更新fork的代码
    robotframework出现错误:Keyword 'AppiumLibrary.Open Application' expected 1 to 2 non-keyword arguments,got 5.
    adb命令积累
    appium测试android环境搭建(win7)
    小明的自留地
    转载:appium踩过的坑
    junit3和junit4的使用区别如下
    Python线程指南
    实现ie低版本支持input type="number"
    LODOP打印开发
  • 原文地址:https://www.cnblogs.com/kyle-he/p/3677985.html
Copyright © 2020-2023  润新知