Board index » cppbuilder » How to modify the same "string" from the [1] position to the end of the line (New problem...)

How to modify the same "string" from the [1] position to the end of the line (New problem...)


2003-08-11 02:49:05 AM
cppbuilder74
hi dear builders,
I've got a problem that was posted here before, Thread-Name:
" How can I insert/modify the same "string" from the [0] position to the end
of the line...? "
Remy post me the below code, I modify it to take user-specific Start and End
of a tag
like: <XML>(beginn is "<" end is ">") I mean insted of "<" and ">" the
user is now able
to define his own Start and End "symbol/char"..
The problem is after the change the function fails with a "invalid Variant
converting"
Where is exactly the problem...?
/*******************************************************************/
AnsiString str;
AnsiString Anfang = Edit1->Text[1], Ende = Edit2->Text[1]; // Is this
the problem...?
frmStringDetails->Memo1->Lines->BeginUpdate();
try
{
for(int i = 0; i < frmStringDetails->Memo1->Lines->Count; i++)
{
str = frmStringDetails->Memo1->Lines->Strings[i];
if(!str.IsEmpty() )
{
if( str[1] == Anfang) // '<'
{
int pos = str.Pos(Ende); // '>'
if( pos != 0 )
{
AnsiString tag = str.SubString(2, pos - 2).Trim();
if( !tag.IsEmpty() )
{
if( str.Pos("</" + tag + ">") == 0 )
{
str += ("</" + tag + ">");
frmStringDetails->Memo1->Lines->Strings[i] =
str;
}
}
}
}
}
}
}
__finally {
frmStringDetails->Memo1->Lines->EndUpdate();
}
/*******************************************************************/
Thanks for any help..
Oren
 
 

Re:How to modify the same "string" from the [1] position to the end of the line (New problem...)

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
The problem is after the change the function fails with
a "invalid Variant converting"
On which line exactly? There are no Variants in use in any of this code.
It is not possible to get a Variant error without using a Variant to begin
with.
Quote
AnsiString Anfang = Edit1->Text[1], Ende = Edit2->Text[1];
You are only allowing the user to specify 1 character each? That code as
you currently have it will fail if either TEdit is empty, as the '[]' will
be out-of-bounds. You need to either test the TEdits to make sure they are
not empty first, or else use SubString() instead:
AnsiString Anfang = Edit1->Text.SubString(1, 1);
AnsiString Ende = Edit2->Text.SubString(1, 1);
Quote
if( str.Pos("</" + tag + ">") == 0 )
Since you are allowing the user to specify his own characters, you should
adjust that line to use them:
if( str.Pos(Anfang + "/" + tag + Ende) == 0 )
Quote
str += ("</" + tag + ">");
Same here:
str += (Anfang + "/" + tag + Ende);
Gambit
 

Re:How to modify the same "string" from the [1] position to the end of the line (New problem...)

Liz & Remy thanks ! Works fantastic now !!!
Oren
 

{smallsort}