点击查看详细介绍

对字符串的末尾编号自动加+1处理,保留前位0的功能函数

nxopen 6年前 1957 10

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


函数功能:对字符串的末尾编号自动加+1处理

函数说明:传递一个带有编号的字符串,返回这个字符串的下一个编号

使用举例:

nextStrNum("005") 将返回 006,

nextStrNum("A0012") 将返回 A0013,

nextStrNum("X08_018") 将返回X08_019


使用场景:对于批量出图纸需要自动的设置编号可能会用到,在CAM加工中批量创建程序组可能会用到等等


函数代码:

//对字符串的末尾编号自动加+1处理
string nextStrNum(string oldstr)
{
    string nextNumstr="";

    char * cBianhao = (char *)(oldstr.c_str());    
    int len = strlen(cBianhao);        
    if (len <= 0)    //判断字符串是否为空
    {
        //为空
    }
    else
    {
        int NumLen = 0;
        for (int i = 1; i <= len; i++)
        {
            NumLen = i;
            if (!(isdigit(cBianhao[len - i])))
            {
                NumLen = NumLen - 1;
                break;
            }
        }
        if (NumLen > 0)
        {
            string  *** ianhao = string(cBianhao);
            int n = NumLen;
            string strRight, strLeft, origstrRight;

●●●请先 登陆注册 后查看●●●

            if(zerostr !="")
            {
                bool iscarry = false;
                double po = intRight; 
                while(po > 1)
                {
                    po = po / 10.0;
                    if(po == 1.0)
                    {
                        iscarry = true;
                        break;
                    }
                }
                if(iscarry)
                {
                    if(origstrRight.length()- zerostr.length() == string(strRight).length()-1)
                    {
                        zerostr.erase(zerostr.end()-1);
                    }
                }
            }

            nextNumstr = strLeft + zerostr + strRight;
        }
    }

    return nextNumstr;
}


3

最新回复 (10)
  • Chenyw VIP会员 6年前
    1

    生命不息,学习不止

  • bao7659535 VIP会员 6年前
    2

    学习一下,谢谢分享

  • T870480535 VIP会员 6年前
    3

    学习一下,谢谢分享

  • 编程刘工 VIP会员 5年前
    4

    学习了,谢谢胡工分享

  • 王牌飞行员 VIP会员 5年前
    5

    学习了,谢谢胡工分享

  • litwo 5年前
    6

    感谢楼主分享,谢谢!

  • songge_2018 VIP会员 5年前
    7

    感谢楼主分享,谢谢!

  • BAO694893367 VIP会员 3年前
    8

    学习了,谢谢胡工分享

  • mask VIP会员 2年前
    9

    感谢楼主分享,谢谢!

  • a970356240 VIP会员 1年前
    10

    学习了,谢谢胡工分享

请登录后发表新帖