本文转载自:http://blog.sina.com.cn/s/blog_605f5b4f0100z3bc.html
C++中:
substr(start, length);//注意第二个参数是长度,表示从start位置起,截取length这么长的字符串
> cat test.cpp
#include<iostream>
#include<string>
using namespace std;
int main(){
string str = "89M11S";
cout << str.substr(3, 3) << endl;
return 0;
}
> ./a.out
11S
JAVA中:
subString(start, stop);//注意第二个参数指终止位置,表示从start位置截取到stop位置的字符串
String test = "89M11S";
System.out.println(test.substring(3, 6));
System.exit(0);
结果:
11S