Created
July 13, 2013 14:53
-
-
Save bongtrop/5990983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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