Is there any (possibly, using a macros) way to get a substring of a string using python-like expression f(i:j)? Or, more specifically, resolve i:j expression into pair of indices i and j? Any ideas?
EDIT: Yes, I need :. Or ;. Basically, something that simple function or macros can't do. Just want to see if it is possible or not.
EDIT: Basically, I want to see if it is widely applicable. For arrays as well, maybe. So the question is more of a "Can I turn i:j to i j", I guess. Doesn't matter is these are std:strings or c-strings.
I hate myself for answering, but ...
#include <iostream>
#include <string>
#define f(x) substr(true?x, false?x)
int main () {
std::string s = "Hello, world";
std::string y = s.f(1:4);
std::cout << y << "\n";
}
Warning: I am a hiring manager. If I ever discover that you use this technique, I will never hire you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With