Cstring C ++查找和替换 [英] Cstring C++ find and replace

查看:209
本文介绍了Cstring C ++查找和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个C ++项目(Microsoft Visual C ++ 2008),这是我的同事多年前开发的,我需要更新一些东西。



我有一个包含json的CString,我需要找到并替换****中存在的4个连续数字的每个组合。



示例字符串



1234567 12 34 78 iioi78ccc8888 aaassd dededeed ed



结果字符串



**** 567 12 34 78 iioi78ccc **** aaassd dededeed ed



你能建议一个能有效做到这一点的功能吗,它与Microsoft Visual C ++ 2008完全兼容。



谢谢。



我尝试了什么:



我的方法是使用RegEX来找到4个连续数字的列表并替换它们但是对Microsoft Visual C ++ 2008的支持是有限的 - 正如我正在阅读的那样。

Hello,

I have a C++ project (Microsoft Visual C++ 2008) that was developed years ago by a colleague of mine and I need to update something.

I have a CString that contains a json and I need to find and replace every combination of 4 consecutive numbers that is present with ****.

Example string

1234567 12 34 78 iioi78ccc8888 aaassd dededeed ed

Resulting string

****567 12 34 78 iioi78ccc**** aaassd dededeed ed

Can you suggest a function that can effectively do this, that is fully compatible with Microsoft Visual C++ 2008.

Thank you.

What I have tried:

My approach would be to use RegEX to find the list of 4 consecutive digits and to replace them but support for Microsoft Visual C++ 2008 is limited – as I was reading.

推荐答案

你不妨写一个简单的这样做的功能(只使用最小状态机在缓冲区上传递一次)。
You might as well write a simple function for doing that (just one pass on the buffer with a minimal state machine).


参见标准C ++库< regex> [ ^ ]


这篇关于Cstring C ++查找和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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