开发者

std::string - get data from start to end

开发者 https://www.devze.com 2022-12-18 05:02 出处:网络
I want to get some data between some 2 indexes. For example, I have string: \"just testing...\" and I need string from 2 till 6. I shoul开发者_如何学God get:

I want to get some data between some 2 indexes. For example, I have string: "just testing..." and I need string from 2 till 6. I shoul开发者_如何学God get: 'st tes'.

What function can do this for me?


Use substr:

std::string myString = "just testing...";

std::string theSubstring = myString.substr(2, 6);

Note that the second parameter is the length of the substring, not an index (your question is a bit unclear, since the substring from 2 to 6 is actually 'st t', not 'st tes').


use the substr method:

std::string theString = "just testing";
std::string theSubstring = theString.substr(2, 4);
0

精彩评论

暂无评论...
验证码 换一张
取 消