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

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

问题描述

我有两个 CString s1CString s2.我需要在 s1 中找到最后一个条目 s2.我可以在 CString 中找到任何方法,例如在 C# LastIndexOf 中.我是 C++ 中的菜鸟.提前致谢.

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天全站免登陆