当前位置: 首页 > news >正文

深圳网站制作功能辽阳网站设计

深圳网站制作功能,辽阳网站设计,网站底部怎么做,网站后台生成htmlFrom#xff1a;http://www.jb51.net/article/55954.htm 1. 用strtok函数进行字符串分割 原型#xff1a; char *strtok(char *str, const char *delim); 功能#xff1a; 分解字符串为一组字符串。 参数说明#xff1a;str为要分解的字符串#xff0c;delim为…Fromhttp://www.jb51.net/article/55954.htm 1. 用strtok函数进行字符串分割 原型       char *strtok(char *str, const char *delim); 功能       分解字符串为一组字符串。 参数说明str为要分解的字符串delim为分隔符字符串。 返回值    从str开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。 其它       strtok函数线程不安全可以使用strtok_r替代。 代码示例 //借助strtok实现split #include string.h #include stdio.hint main() {char chArry[] one two three,four * five;const char *d ,*;char *p;p strtok(s,d);while(p ! NULL){printf(%s\n, p);pstrtok(NULL, d);}return 0; } 2. 用STL进行字符串的分割 涉及到string类的两个函数find和substr 1、find函数         原型       size_t find ( const string str, size_t pos 0 ) const;         功能       查找子字符串第一次出现的位置。         参数说明str为子字符串pos为初始查找位置。         返回值    找到的话返回第一次出现的位置否则返回string::npos 2、substr函数         原型       string substr ( size_t pos 0, size_t n npos ) const;         功能       获得子字符串。         参数说明pos为起始位置默认为0n为结束位置默认为npos         返回值    子字符串 示例代码 #include iostream #include string #include vector //字符串分割函数 std::vectorstd::string split(std::string str,std::string pattern) { std::string::size_type pos; std::vectorstd::string result; strpattern;//扩展字符串以方便操作 int sizestr.size(); for(int i0; isize; i) { posstr.find(pattern,i); if(possize) { std::string sstr.substr(i,pos-i); result.push_back(s); ipospattern.size()-1; } } return result; } int main() { std::string str; std::coutPlease input str:std::endl; //std::cinstr; getline(std::cin,str); std::string pattern; std::coutPlease input pattern:std::endl; //std::cinpattern; getline(std::cin,pattern);//用于获取含空格的字符串 std::vectorstd::string resultsplit(str,pattern); std::coutThe result:std::endl; for(int i0; iresult.size(); i) { std::coutresult[i]std::endl; } std::cin.get(); std::cin.get(); return 0; } find_first_not_of #includestring #includevector #includeiostream using namespace std;void Tokenize(const string str, vectorstring tokens, const string delimiters) {// Skip delimiters at beginning.string::size_type lastPos str.find_first_not_of(delimiters, 0);// Find first non-delimiter.string::size_type pos str.find_first_of(delimiters, lastPos);while (string::npos ! pos || string::npos ! lastPos){// Found a token, add it to the vector.tokens.push_back(str.substr(lastPos, pos - lastPos));// Skip delimiters. Note the not_oflastPos str.find_first_not_of(delimiters, pos);// Find next non-delimiterpos str.find_first_of(delimiters, lastPos);} } int main(int argc, char *argv[]) {string str(aaabbbcccddd);vectorstringtokens;Tokenize(str, tokens, );for( int i 0; i tokens.size() ; i ){cout tokens[i] endl;}return 0; } 3. 用Boost进行字符串的分割 用boost库的正则表达式实现字符串分割 示例代码 #include iostream #include cassert #include vector #include string #include boost/regex.hppstd::vectorstd::string split(std::string str,std::string s) {boost::regex reg(s.c_str());std::vectorstd::string vec;boost::sregex_token_iterator it(str.begin(),str.end(),reg,-1);boost::sregex_token_iterator end;while(it!end){vec.push_back(*it);}return vec; } int main() {std::string str,s;strsss/ddd/ggg/hh;s/;std::vectorstd::string vecsplit(str,s);for(int i0,sizevec.size();isize;i){std::coutvec[i]std::endl;}std::cin.get();std::cin.get();return 0; } boost里面有自带的split的函数如果用boost的话还是直接用split的好 示例代码 #include iostream #include string #include vector #include boost/algorithm/string/classification.hpp #include boost/algorithm/string/split.hppusing namespace std;int main() {string s sss/ddd,ggg;vectorstring vStr;boost::split( vStr, s, boost::is_any_of( ,/ ), boost::token_compress_on );for( vectorstring::iterator it vStr.begin(); it ! vStr.end(); it )cout *it endl;return 0; }
http://wiki.neutronadmin.com/news/21970/

相关文章:

  • 网站维护流程图wordpress pdf
  • 张家港百度网站推广网站优化哪个公司好
  • 人人设计网官方网站沈阳今天最新通知
  • 有什么专门做电子琴音乐的网站淘宝联盟优惠券网站建设
  • 网站建设标准合同书网站怎样设计网址
  • 网上做家教的网站如何进行网络营销
  • 怎么查网站建设时间公司企业网站建设教程
  • 做网站费用上海好的做网站的
  • 义乌制作网站开发本地wordpress后台很慢
  • 网站设计在线培训wordpress图片上传卡住
  • 网站备案过期赣州人事人才网
  • 做网站需要什么花费响应式网站建设代理
  • 易讯网络网站建设wordpress插件重写
  • 沧州网站运营网页设计师职业资格证书
  • 成都网站改版公司软件外包app
  • 网站建设与管理专业介绍wordpress数据库教程
  • 公司建设网站费用直接列支旅行社酒店分销平台
  • 网页网站设计用什么软件网站建设程序都有哪些
  • 建设网站网页打不开网站建设技术维护一年合同
  • 网站数据库空间邗江建设局网站资料下载
  • 网站空间1g多少钱一年设计公司装修图
  • 手机和pc合一的网站cms系统干什么的
  • 域名访问网站是什么意思做一个wordpress模板下载地址
  • 做游戏排行榜的网站模板去哪个网站找题目给孩子做
  • 免费自助建站代理免费logo设计图片软件
  • 百度推广弄个网站头像要钱吗?广西壮族自治区人口
  • 幼儿做爰网站怎么做淘宝联盟网站推广
  • 建立网站步骤知名外贸网站建设公司
  • 怎么创建免费的网站无需本金十分钟赚800
  • 上杭县建设局网站许昌网站建设找汉狮