Skip to content

Instantly share code, notes, and snippets.

@bongtrop
Created July 13, 2013 14:53
Show Gist options
  • Save bongtrop/5990983 to your computer and use it in GitHub Desktop.
Save bongtrop/5990983 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
//reverse string
string bt_reverse(string input) {
return string(input.rbegin(),input.rend());
}
//replace string
//input: input, from, to, num
//output: string
string bt_replace(string input, string from, string to, int type) {
if (type==0) {
while (input.find(from)!=string::npos) {
input.replace(input.find(from),from.length(),to);
}
} else {
for (int i=0;i<type;i++) {
input.replace(input.find(from),from.length(),to);
}
}
return input;
}
//split string
//input: address output, input, cut
//output: size of word
int bt_split(string *output, string input, string cut) {
char *pch, ichar[1000], icut[1000];
int c=0;
strcpy(ichar,input.c_str());
strcpy(icut,cut.c_str());
pch = strtok(ichar, icut);
while (pch != NULL) {
output[c++]=string(pch);
pch = strtok (NULL, icut);
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment