mirror of https://github.com/eeeneko/ovo.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
呓喵酱
e140aab5f1
|
5 years ago | |
---|---|---|
.. | ||
README.md | 5 years ago |
README.md
Class ovo::string
void ovo::String::split(const std::string& s, std::vectorstd::string& v, const std::string& c)
Split the string.
replaceStr
void replaceStr(string& str, const string fromStr = " ", const string toStr = "", int pos = 0, const int end = 99999)
This function can search for a specific string fromStr in a string str between an interval (default the entire string), and replace fromStr with another string toStr.
params
- string str The string need to be changed
- string fromStr The string will be replaced by toStr (default space)
- string toStr The string that will replace fromStr (default empty)
- int pos The function will start searching for fromStr from position pos of str (default 0)
- int end The function will finish searching for fromStr at position end of str (default 99999)
example 1: Using default value
#include<iostream>
#include<string>
using namespace std;
void replaceStr(string& str, const string fromStr = " ", const string toStr = "", int pos = 0, const int end = 99999)
{
while(pos > -1 && pos < end){
pos = str.find(fromStr, pos);
if(pos > -1 && pos < end){
str.replace(pos++, fromStr.length(), toStr);
}
}
}
int main()
{
string str1 = "aallaaa bbbbbbb cccccccc ddddddddd";
replaceStr(str1);
cout << str1 << endl;
}
The string print on the screen is
aallaaabbbbbbbccccccccddddddddd
example 2: using setup value
#include<iostream>
#include<string>
using namespace std;
void replaceStr(string& str, const string fromStr = " ", const string toStr = "", int pos = 0, const int end = 99999)
{
while(pos > -1 && pos < end){
pos = str.find(fromStr, pos);
if(pos > -1 && pos < end){
str.replace(pos++, fromStr.length(), toStr);
}
}
}
int main()
{
string str1 = "aallaaa bbbbbbb cccccccc ddddddddd";
replaceStr(str1, "bbb", "22", 8, 9);
cout << str1 << endl;
}
The string print on the screen is
aallaaa 22bbbb cccccccc ddddddddd