Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 9-May-18 1:44am
v2
Comments
[no name] 9-May-18 7:33am    
"support for Microsoft Visual C++ 2008 is limited"
In what way limited?
micutzu 9-May-18 7:44am    
<regex>
Visual Studio 2010

You might as well write a simple function for doing that (just one pass on the buffer with a minimal state machine).
 
Share this answer
 
Comments
micutzu 9-May-18 7:48am    
Right - but how to find (without regex) a combination of 4 consecutive numbers - like 8989 using Cstring functions - since Visual Studio 2008 is "jsut" 10 years old :)
CPallini 9-May-18 7:54am    
looping over the buffer while taking note of 'last digit index'.
 
Share this answer
 
Comments
micutzu 9-May-18 7:44am    
<regex>
Visual Studio 2010

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900