add delimiter into string
来源:互联网 发布:上海耀姚贸易 知乎 编辑:程序博客网 时间:2024/06/07 20:29
#include <iostream>#include <string>using namespace std;string formatString(const string& str, int segWidth, char delimiter){ size_t size = str.size(); size_t pos = 0; string result; if (size > 0 && segWidth > 0 && size > segWidth) { while(pos < size) { result += str.substr(pos, segWidth); pos += segWidth; if (pos < size) { result += delimiter; } //cout << result<<endl; } } else { result = str; } return result;}int main(int argc, char* argv[]){ string s1 = "a3dfae18d0dba9027e56591122f3ef84"; string s2 = formatString(s1, 4, '-'); cout << "s1: " << s1 << "\ns2: " << s2<<endl; return 0;}
output:
s2: a3df-ae18-d0db-a902-7e56-5911-22f3-ef84
0 0
- add delimiter into string
- delimiter
- add string
- Go deep into String
- 巧用exec语句修改string.Template的delimiter
- SQL0010N does not have an ending string delimiter
- add new features into the interceptor pattern
- How to add SMSC feature into Android
- Add a new node into the cluster!
- Add check box into the datatable
- add ScanDestinations into ScanAvailableEvent in WSDAPI
- Add third-party code into your project
- How to add project into Android BSP
- Add IPAD control function into shairplay
- Auto add log into java file
- Add zip into GIT Bash on Windows
- LeetCode[String]: Add Binary
- leetcode---Add Binary---string
- Linux shell脚本全面学习
- 多次执行Hibernate query.list()后,发现会卡在这一句的问题。
- 解决MacOS多语言文件夹(文稿变成Documents等)配置丢失的办法
- 第7周项目3求三个数的最大值
- 数字证书创建(包括根和子证书)
- add delimiter into string
- discuz(dz) SSO(单点,同歩,异步)登录
- 国内O2O运营模式逐渐改变我们生活方式
- Shell基础知识
- ubuntu 下 Pureftpd 常用配置
- HDOJ 4975 A simple Gaussian elimination problem.
- 收藏总结-关于jquery mobile动态刷新listview的几种方法以及其他标签的refresh
- pureftpd ubuntu配置指南
- 一个C#类多态与隐藏(new)方法的结果分析