CString找到最后一个条目 [英] CString find the last entry

查看:230
本文介绍了CString找到最后一个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 CString s1 CString s2 。我需要找到s1中的最后一个条目s2。
我可以找到任何metod在CString像在C#LastIndexOf。
我在c ++中的nooby。提前感谢。

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.

推荐答案

CString 没有这样的功能。你必须自己写,例如

CString has no such function. You have to write it yourself, e.g.

int LastIndexOf(const CString& s1, const CString& s2)
  {
  int found = -1;
  int next_pos = 0;
  for (;;)
    {
    next_pos = s1.Find(s2, next_pos);
    if (next_pos == -1)
      return found;

    found = next_pos;
    };
  }

更好的算法会反转字符串,练习。

A more optimal algorithm would reverse the strings first, I'm leaving that as an exercise.

这篇关于CString找到最后一个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆