zoukankan      html  css  js  c++  java
  • 从字符串中取数字(1-99) 不用正则表达式

    // dwd.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include<iostream>
    int get_XYMN_Value(char * buf,int &offset)
    {
        unsigned short len=strlen(buf);
        int a=0,b=0;
        bool flag=false;
        while(len)
        {
            if((*buf)>48&&(*buf)<=59) //(0,9]
            {
              if(!flag)
              {
                 a=*buf;
                 flag=true;
                 buf++;
                 offset++;
                 continue;
              }
              if(flag)
              {
                b=*buf;
                return (a*10+b);
              }
            }
            else
            {
                if(a!=0)
                  return a;
                else
                  flag=false;
            }
            buf++;
            offset++;
            len=strlen(buf);
        }
        
        if(len==0)
            return a;
        return 0;
    }
    
    int main(int argc, char* argv[])
    {
        char * buf="91,92,93,94,5,6,7,8,9";
        int len=strlen(buf);
        int offset=1;
        int a=0;
        char b=0;
        while(len)
        {
            a=get_XYMN_Value(buf,offset);
            b=a;
            std::cout<<a<<" "<<b<<std::endl;
            buf=buf+offset;
            offset=1;
            len=strlen(buf);
        }
    
        std::cout<<"......好戏开场"<<std::endl;
        
        {
          char *content="1,2,3,4,5";
          unsigned short len=strlen(content);
          int x=0,y=0,m=0,n=0;
          char ascii_x=0,ascii_y=0,ascii_m=0,ascii_n=0;
          int step=1;
          int offset=1;
          while(len)
          {
            switch(step)
            {
               case 1:
               {
                 ascii_x=get_XYMN_Value(content,offset);
                 step=2;
                 break;
               }
               case 2:
               {
                 ascii_y=get_XYMN_Value(content,offset);
                 step=3;
                 break;
               }
               case 3:
               {
                 ascii_m=get_XYMN_Value(content,offset);
                 step=4;
                 break;
               }
               case 4:
               {
                 ascii_n=get_XYMN_Value(content,offset);
                 len=0;
                 break;
               }
            }
             content =content + offset;
             offset=1;
             len=strlen(content);
          
          }//end while
          std::cout<<ascii_x<<std::endl;
          std::cout<<ascii_y<<std::endl;
          std::cout<<ascii_m<<std::endl;
          std::cout<<ascii_n<<std::endl;
    
        }//end {
        return 0;
    }
  • 相关阅读:
    thymeleaf是用于编写html模版的编程语言(工具语言)
    前端页面生成技术
    算法是用逻辑语言描述的问题求解步骤
    模板引擎
    递归与分形
    泛型的特征-为什么使用泛型(集合理论)
    算法沉思录-算法的描述(草稿)
    计算机语言发展史
    pHP生成唯一单号
    laravel实现批量添加数据
  • 原文地址:https://www.cnblogs.com/azbane/p/9004331.html
Copyright © 2011-2022 走看看