I’m using windows 7 and Visual C++. I have a console program and I am trying to trim a string at the begining and the end. TrimLeft() and TrimRight() don’t seem to work without MFC. Here is what I have so far.
pBrowser->get_LocationURL(&bstr);
wprintf(L" URL: %s\n\n", bstr);
SysFreeString(bstr);
std::wstring s;
s = bstr;
s.TrimStart("http://");
s.TrimEnd("/*");
wprintf(L" URL: %s\n\n", s);
I’m trying to go from this:
to this:
“www.stackoverflow.com”
You should use
find/rfind(right find – find from right) andsubstr(sub string) in sequence to do what you need to do.1) Find the index of the first pattern (such as http://) with find – you already know its length, add this to the start index as the origo of your trimmed string
2) Find the last index of the ending pattern with find
3) Create a substring from the origo to the end using
substrThese methods are all in std::string