字符串基本操作2
2016-09-22 21:59
92 查看
//排序字符串,使得字符串大写在前,小写在后 void StrSort(char* s) { int len=0; while(s[len]!='\0') len++; int index=-1; for(int i=0;i<len;i++) { if(s[i]>='A'&&s[i]<='Z') { char tem=s[++index]; s[index]=s[i]; s[i]=tem; } } }
#include<limits> /* * 实现atoi函数 * 1.数值越界 * 2.正负数 * 3.字符串结束标志 * */ int StringToInt(string& str) { if(str.length()==0) return 0; //清除空格 int i=0; for(;str[i]!=' ';i++) break; //设置符号标志位 bool flag=false; if(str[i]=='-') { i++; flag=true; } //转整数 int result=0; for(;str[i]!='\0';i++) { if(str[i]<'0'||str[i]>'9') return 0; int tem = str[i]-'0'; if(!flag && numeric_limits<int>::max()-result*10<=tem) return numeric_limits<int>::max(); if(flag && numeric_limits<int>::min()+result*10>=tem*-1) return numeric_limits<int>::min(); result=result*10+tem; } if(flag) return 0-result; else return result; }
相关文章推荐
- 字符串的一些基本操作
- SQL字符串基本操作汇总
- 黑马程序员---操作字符串、封装基本数据
- 【读书笔记】std::string的基本操作 与字符串数组的区别
- Python学习笔记:字符串基本操作
- 《面向对象程序设计与VC++实现》--liwei_2_1(字符串基本操作 求长度、复制、连接)
- 数据结构:字符串的基本操作
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- Foundation的基本操作—字符串、数组、字典、集合
- object-c中字符串基本操作
- c++中的字符串基本操作
- vector基本操作|随机生成乱序字符串
- Bash基本字符串操作
- python--序列的基本概念和操作(序列:列表、元组、字符串)
- SQL字符串基本操作汇总
- 《Windows内核编程》---内核模式下字符串的基本操作
- Perl字符串基本操作详解
- 《Windows内核编程》---内核模式下字符串的基本操作
- php字符串基本操作
- object-c中子字符串(NSMutableString)基本操作