How do you use the find_iterator to do in-place replacements?

Hi all. I have the split_iterator working as intended on a string, but I don't see how to use the range it returns to change the string directly without copying it. For example, I want to do an erase_all on a range, but that function won't take a range. Anybody have an example of how to do this? Thanks!

G S a écrit :
Hi all.
I have the split_iterator working as intended on a string, but I don't see how to use the range it returns to change the string directly without copying it. For example, I want to do an erase_all on a range, but that function won't take a range.
The first argument is a container you want to erase the subrange from, and the second argument is the subrange in question that you want to erase.

Mathias Gaunard a écrit :
G S a écrit :
Hi all.
I have the split_iterator working as intended on a string, but I don't see how to use the range it returns to change the string directly without copying it. For example, I want to do an erase_all on a range, but that function won't take a range.
The first argument is a container you want to erase the subrange from, and the second argument is the subrange in question that you want to erase.
Err ignore this, I had badly read the docs. erase_all will erase all subranges of the input string that are equal to the passed range. To erase a specific subrange, simply use the erase member function of your container.

Thanks, Mathias, but I don't want to erase the entire range. I want to replace all the occurrences of a specific character in that range. For example, I have a line of text where some sections fall between quotes. I want to replace all commas within these quoted sections. I can find the quoted sections with split_iterator, but none of Boost's replacement functions seem to take a range (which I find a little surprising).

G S wrote:
Thanks, Mathias, but I don't want to erase the entire range. I want to replace all the occurrences of a specific character in that range.
For example, I have a line of text where some sections fall between quotes. I want to replace all commas within these quoted sections. I can find the quoted sections with split_iterator, but none of Boost's replacement functions seem to take a range (which I find a little surprising).
replace_range(your_container, your_comma_range, what_you_want_to_put_instead) Use find_iterator to get all your_comma_ranges.

Thanks, but I don't think that's going to work. That's going to replace the everything in the range. I only want to replace the commas within the range. In a line like this: column1, column2, "value1, value2, value3, value4", column4, column5 I want to replace only the commas that fall between quotes.
participants (2)
-
G S
-
Mathias Gaunard