字符串截取 c++
来源:互联网 发布:淘宝运营师培训 怎么考 编辑:程序博客网 时间:2024/06/16 21:36
C++ 字符串截取相关函数讲解
CString2 CString str = _T("abcdefghijklmn");
3 res = str.Mid(2,3); //从第3位字母开始,共取3个字符
4 ASSERT(res == _T("cde"));
5
6 res = str.Left(3); //从左边数起,共取3个字符
7 ASSERT(res == _T("abc"));
8
9 res = str.Right(3); //从右边数起,共取3个字符
10 ASSERT(res == _T("lmn"));
11
12 res = str.SpanIncluding(_T("edcba")); //遇到参数里没有的字符即停下,返回停下之前的字符串
13 ASSERT(res == _T("abcde"));
14
15 res = str.SpanExcluding(_T("fgb")); //遇到参数里面有的字符即停下,返回停下之前的字符串
16 ASSERT(res == _T("a"));
String
截取子串
s.substr(pos, n) 截取s中从pos开始(包括0)的n个字符的子串,并返回
s.substr(pos) 截取s中从从pos开始(包括0)到末尾的所有字符的子串,并返回
附加:
截取字符串子串 (1)(GBK)
*
* @param string $str 原始字符串
* @param int $len 需要截取字符串的长度
* @return string 返回截取到的字符串
*/
function GBSubstr($str, $len){
}
一个这样的字符串:“123,456,789,0”。把他截取成这样的字符串数组[123],[456],[789],[0]。众所周知c++默认没有提供这样功能的函数,下面我们自己来实现它
不多说直接上代码:
C++代码
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<string> splitEx(conststring& src, stringseparate_character)
{
}
int _tmain(int argc, _TCHAR*argv[])
{
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> splitEx(conststring& src, string separate_character)
{
}
int _tmain(int argc, _TCHAR* argv[])
{
}
输出:
123
456
789
0
888
- 字符串截取(C#)
- C 截取字符串
- C -- 截取字符串
- c语言 字符串截取
- C#-截取字符串----ShinePans
- C#---截取字符串
- C 字符串截取
- C字符串截取函数
- c++Csring 截取字符串
- C 截取字符串
- c字符串截取
- C语言截取字符串
- C语言 字符串截取
- c中字符串截取
- c++MFC 截取字符串
- [C#][转][string 字符串截取
- 【C语言】截取字符串实现
- jstl-c标签截取字符串
- Dialer拨号定制功能
- 【二】线性表的链式存储结构
- 【1. 概述】开源入侵检测系统OSSEC详解
- 在qemu-system-arm模拟器启动initramfs根文件系统内核
- iOS "vtable for XXX", referenced from:
- 字符串截取 c++
- Android HttpClient基本使用方法
- hello, csdn
- 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法
- Java的不定长参数和Python的不定长参数对比
- 读取生产订单 记入文档的货物移动明细
- 如何做好长尾词引流
- 20050519
- 商银行信用卡中心的微信公共帐号,帐号绑定功能是如何实现的?