I'm trying to convert part of a string. Say I have a bunch of strings and I want to search through all of them, and whenever one of them have the string "34" contained within, I want to convert that part of the string to "XX". Imagine the following:

#include <string>
#include <iostream>
using namespace std;
int main()
{
      string a = "1234";
      string b = "2345";
      string c = "3456";
      string d = "4567";
      //...
      cout << a << "," << b << "," << c << "," << d << endl; 
      return 0;
}

I want the output to be: "12XX,2XX5,XX56,4567"

How do I do this? I'm a little lost here...

EDIT:
So, I think I'm going to go for string::replace along with string::find. How exactly do I use replace to do "34" = "XX" though? Don't I need to know the position of "34"? Is there a way to do with without an explicit iterator?

REDIT:
I see now that .find() actually returns the position of the found string. Seems that I've answered my own question...

(I'm writing a HexDump -> assembler file converter by the way)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.