Alright, here's the problem. I have a simple function that takes an input string, a starting delimeter and an ending delimeter, and returns the string in between.
It works fine except for a particular case. This is the output I get:
std::string getBetween(std::string buffer, std::string first, std::string second)
std::string input = buffer;
int fpos = input.find(first, 0);
int spos = input.find(second, fpos);
fpos += 1;
spos -= 1;
int length = (spos - fpos) + 1;
std::cout<<"POS: "<<fpos<<" - "<<spos<<"\n";
output = input.substr(fpos, length);
The problem is in the 3rd section (and the last one too, though that doesn't matter so much). I don't know why this is happening, could it be a problem with the input or is it the function itself? Any help would be appreciated.
POS: 4 - 9
POS: 4 - 35
INPUT: set(newvar, "testing print function");
OUTPUT: newvar, "testing print function"
POS: 1 - -1
INPUT: "testing print function"
OUTPUT: testing print function"
POS: 6 - 11
POS: 0 - -2
edit: Arghh! I think I just realised the problem within about 10 seconds of posting! I forgot to check if it was found or not!! >.<
Alright I got it fixed, problem was I was searching for the end string starting from fpos instead of fpos+1!