如何在 C++ 中使用 substr 从右侧获取字符串
how to use substr get string from right hand side in c++
例如469111252我有一串数字,我知道如何从左侧拆分,但如何使用 substr 从右侧拆分它?
如果数字每个节点 = 2
左起 46 91 11 25 2
但我想从右边得到 52 12 11 69 4
//left hand side parse
for (int i=0;i<num.length(); i+=digitsPerNode) {
splitNum = num.substr(i,digitsPerNode);
}
从上到下计数,而不是从下到上计数。
int numlength=num.length();
if(numlength%2==1)
numlength+=1;
for(int i=numlength;i>=0;i-=digitsPerNode)
{
splitNum = num.substr(i,digitsPerNode);
{
string a = "1234567890-=4";
for (int i = a.length() - 2; i >= -1; i = i - 2)
{
if (i < 0) cout << a.substr(i+1, 1) << endl;
else cout << a.substr(i, 2) << endl;
}
我找到了具有反向函数的解决方案
DoublyLinkedList::DoublyLinkedList(string value, string dPerNode)
{
digitsPerNode = stoi(dPerNode);
string subString;
reverse(value.begin(), value.end());
for (int i = 0; i <= value.length(); i += digitsPerNode)
{
//cut string by digitsPerNode Ex: 3 500 123 412
subString = value.substr(i, digitsPerNode);
reverse(subString.begin(), subString.end());
insertAtHead(subString);
}
}
相关文章:
- 获取字符串的长度并将其分配给数组
- 调用CreateProcess()并获取字符串的返回值
- 你如何从 Boost Spirit X3 词法解析器中获取字符串?
- 使用 ReadProcessMemory 获取字符串值的访问冲突
- 如何从输入中获取字符串向量?
- 如何获取字符串输入n次?
- property_tree获取字符串形式的数组值
- 使用 ctypes 和 wchar_t 时如何从 C++ 获取字符串到 python?
- 获取字符串大小的各种方法之间的比较
- 方法获取字符串
- 在getline()之后获取字符串
- 为什么我的拆卸C 代码使用指令指针和偏移来获取字符串文字
- 无法使用 Poco 获取字符串的路径
- 如何在qtablewidget中获取字符串的行号
- 如何获取字符串和字节进行比较
- 恒定字符阵列的获取字符串长度函数(strlen)不是恒定表达式
- 我需要创建一个函数来获取字符串中的这些数字
- 如何从地址获取字符串?
- 为什么即使尚未初始化,获取字符串[0]也是有效的?
- 获取C++字符串的位