
substr(C++语言函式)
substr是C++语言函式,主要功能是複製子字元串,要求从指定位置开始,并具有指定的长度。如果没有指定长度_Count或_Count+_Off超出了源字元串的长度,则子字元串将延续到源字元串的结尾。
基本介绍
- 中文名:substr
- 来源:C++语言函式
- 主要功能:複製子字元串
- 要求:从指定位置开始等
定义和用法
basic_string::substr
basic_string substr(size_type _Off = 0,size_type _Count = npos) const;
参数
_Off
所需的子字元串的起始位置。字元串中第一个字元的索引为 0,默认值为0.
_Count
複製的字元数目
返回值
一个子字元串,从其指定的位置开始
示例
Code : C++中 的代码如下
#include<string>#include<iostream>using namespace std;int main(){ string str1("Heterological paradoxes are persistent."); cout<<"The original string str1 is:"<<endl; cout<<str1<<endl; basic_string<char>str2=str1.substr(6,7); cout<<"The substring str1 copied is:"<<str2<<endl; basic_string<char>str3=str1.substr(); cout<<"The default substring str3 is:"<<endl; cout<<str3<<endl; cout<<"which is the entire original string."<<endl; return 0;}
输出结果:
The original string str1 is:
Heterological paradoxes are persistent.
The substring str1 copied is: logical
The default substring str3 is:
Heterological paradoxes are persistent.
which is the entire original string.
}
在oracle中的用法:
SUBSTR(:NEW.FLAGSTATUS,17,1)
其中参数依次是 ( 开始,长度),并返回子串。
转载请注明出处海之美文 » substr(C++语言函式)