how to strip 0x1F from an AnsiString?

E

Elmar Baumann

Does anyone have a snippet/solution to remove escape-sequences from
AnsiStrings?

thanks in advance . . .

Elmar Baumann
 
J

James Kanze

What are "AnsiStrings"? Instances of the class AnsiString?
Generally, you just do
<yourstringtypehere> str; /// your string
...
<yourstringtypehere>::iterator it = str.begin();
while (it != str.end()) {
if (*it == char_to_strip)
it = str.erase(it); // or str.erase(it++);
else
++it;
}

Wouldn't remove_if be a better solution?

Also worth noting: he mentionned "sequences". Your predicate
would have to have state, so that you could remove the 'B' as
well in something like <ESC>B (supposing that's what he meant by
escape sequences). And since predicates with mutable state aren't
formally guaranteed (the function can make and use whatever
copies of the predicate it wants), you need some sort of
indirection, so that all copies of the predicate share the same
state. (In practice, of course, just putting the state in the
predicate is likely to work. Implementations don't actually
make copies where it isn't necessary.)

(I'm pretty sure that all of the control sequences end with a
letter, and that letters can't occur within them, so the state
machine to remove them would be pretty simple.)
 
E

Elmar Baumann

thanks for answers here, i know it is not really c++ like
but i figured out that i made a mistake for searching an
escaped "\0x1F" - that don't work - it must be "\x1F".

i stripped it following:

int pos;
AnsiString Input = "this is an escaped 0x1F text";

do
{
if(Input.Pos("\x1F"))
{
pos = Input.Pos("\x1F");
Input.Delete(pos,1);
}
}
while(Input.Pos("\x1F") > NULL);


I'm sorry to bother you in this c++ group, i know i'm a bit
on a wrong newsgroup here - but ty again for answering c++ like.

Elmar Baumann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top