zoukankan      html  css  js  c++  java
  • 标准c++去 string 对象 所有空格%%%%%%%%%%去 左右空格代码,在网上找半天,不如自己写的好

    str.erase(remove_if(str.begin(),str.end(),ptr_fun(isspace)),str.end());
    谁有更好的可以发上来丫
    求去左右空格的代码。
     
        TCHAR tempName[256]={0};
        TCHAR tempType[256]={0};
        fscanf(fp,"%s",temp);//得到字段名字
        //continue;
        for(int i=0;i<strlen(temp);i++){
          tempName[i] = temp[i];
        }
        fgets(temp,256,fp);//得到字段类型
        for(int i=0;i<strlen(temp);i++){
          tempType[i] = temp[i];
        }
        Trim(tempType);
        Trim(tempName);


    //去左空格函数
    TCHAR* CreadmifDoc:: lTrim(TCHAR *temp){//*temp==temp[0]
     int len = strlen(temp);
     TCHAR tempStr[256]={0};
     for(int i = 0;i<len-1;i++)
     {
      if(temp[i]!=' '){
       for(int j=0;i<len-1;j++,i++){
        tempStr[j] = temp[i];
       }
      break;
      }
     }
     return tempStr;
    }
    //去右空格函数
    TCHAR* CreadmifDoc::rTrim(TCHAR *temp){
     int len = strlen(temp); 
     for( int i = len;i>=0;i--){
      if(temp[i-2]!=' '){//temp[i-2]为倒数第二个元素,temp[i-1]=='\0'
       temp[i]='\0';
       break;//结束符把字符数组截断
      }
     }
    return temp;
    }

    TCHAR* CreadmifDoc::Trim(TCHAR *temp){
    return lTrim(rTrim(temp));
    }

  • 相关阅读:
    mysql优化——语句优化小技巧
    mysql优化——索引与索引优化
    Mysql存储引擎
    Mysql优化技术
    数据库设计——三范式
    java多线程(二)——用到的设计模式
    java多线程(一)
    ubuntu下如何查看用户登录及用户操作相关信息
    hdu 2546
    hdu 2955
  • 原文地址:https://www.cnblogs.com/8586/p/1244375.html
Copyright © 2011-2022 走看看