I have two CString s1
and CString s2
. I need find the last entry s2 in s1.
I can find any metod in CString like in C# LastIndexOf.
I am nooby in c++. Thanks in advance.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
you don't need implement a self function. std has provide a function: std::string::find_last_of. for example:
i adopted the answer from Andrey (to increment the next_pos, seems to cause an endless loop without it). aaand, since i don't have enough repu points yet (can't comment) i'll post it as a separate answer:
CString is I think part of the "Microsoft Foundation Class Library" and is not Standard C++. There is a reference including methods here:
http://msdn.microsoft.com/en-us/library/aa315043%28v=vs.60%29.aspx
I don't see anything to turn that directly into a std::string (which has a lot more methods), but it probably is not so hard, either (search for "CString to std::string" and you'll find some stuff).
Although they are presumably related, don't confuse this with a c-string, which is an array of
chars
from Standard C included in Standard C++.CString
has no such function. You have to write it yourself, e.g.A more optimal algorithm would reverse the strings first, I'm leaving that as an exercise.
There is no
CString
method to directly address your question. However, you can use a combination ofCString::ReverseFind
+_tcsncmp
to first locate next occurrence of last character of substring and, if found, compare the whole substring from there.