Re:Anyone familiar with the std:: search and std::replace
Quote
> char* Sequence;
> int ByteCount = EditBytes->Text.Length();
> Sequence = new char[ ByteCount ];
> strncpy( Sequence, EditBytes->Text.c_str(), ByteCount );
> BYTE* Pos = std::search( MemoryStreamBuffer, PastTheEnd, Sequence,
> Sequence + sizeof(Sequence) );
I think you have a bug here. You better inspect the value of sizeof(Sequence).
Sequence is a pointer. sizeof(Sequence) is going to be 4 bytes, regardless of how
many characters are in the string.
My personal opinion is that Sequence should include the null-terminator. That way,
you could use strlen instead of sizeof. You don't want to include the null terminator
in your search, but that does not mean that you can't have a null terminator on your
string.
Quote
> // Add a replace here
The generic replace algorithm replaces individual elements in the container, not a
range of elements. In your case, an individual element is a character. If you wanted
to replace all 'b' characters with 'Z' characters, you could user std::replace.
However, I don't think this is what your are looking for. You probably want to
replace the string "foo" with "FooBar". std::replace can't help you there.
You need to erase the original matching characters, and then insert the new
characters somehow. Beware that your memory stream goofs this up because there is a
good chance that you will need to grow the memory stream during the replace. Since
the STL algorithms have no knowledge that your memory is being managed by the memory
stream, there is a good chance that an AV will occur. A vector or list would make
this easier.
Your question ended up being more about the STL than the VCL. STL questions typically
go in the language group.
Harold Howe [TeamB]
http://www.bcbdev.com