-
October 24th, 2009, 05:16 AM
#1
Boost Replace Function
Hey everyone, I'm messing around with boost (learning about their lexical parser anything Boost can do with strings), and I can use the replace_all function, but is there a function to replace only the current instance of the word that the line is reading?
For example, when I use the following code:
Code:
while ( !Input.eof ( ) )
{
getline ( Input, String );
boost::replace_all ( String, "test2", ToReplaceStringWith );
outf << String << endl
}
of course it replaces every instance of "test2" in the text file. But I actually want to replace "test2" only line by line, rather than all at once. That way, lets say I can change "test2" to "test22" in the first instance, and the next time I run into it I can change "test2" to "aweometest" or something of the sort.
I looked a little into regex_replace, but would that do what I want? How would I replace the replace_all function with regex_replace if it will do what I want?
-
October 24th, 2009, 06:25 AM
#2
Re: Boost Replace Function
Originally Posted by Rehorav
But I actually want to replace "test2" only line by line, rather than all at once.
That's exactly what your code does.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
October 24th, 2009, 06:28 AM
#3
Re: Boost Replace Function
How would I make it stop after the first occurrence though?
-
October 24th, 2009, 07:21 AM
#4
Re: Boost Replace Function
Originally Posted by Rehorav
How would I make it stop after the first occurrence though?
boost::replace_first
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|