Board index » cppbuilder » Repost (no replays): How can I delete strings depending on their length in a Memo or RichEdit ??

Repost (no replays): How can I delete strings depending on their length in a Memo or RichEdit ??


2003-09-06 09:05:27 AM
cppbuilder55
hi dear builders,
I got one problem that drives me crazy for several days..
In a RichEdit I got the following text:
________________________________________________
xxxx 43634735687 5 ighkgchb xxxx cxghxgvh 6976793
ghhhhhhhhhhhhhhhhhhhhhhhh
sdsss s ,,,,, ::::: --------------------- trrrr 4332
------ooooooooooijkuuuuuuuugz r e xxxx ddddddd
________________________________________________
Now, I have to delete several strings that their length is less (< )
than 5...
that means ALL strings that are seperated by a space " " or by CRLF's..
How can I do that ??
This works only if the string name is known, NOT the length:
/*************************************************/
AnsiString AString = txtSuchen->Text;
AnsiString BString = txtErstzen->Text;
Memo1->Lines->Text = StringReplace(Memo1->Lines->Text,
AString,BString, TReplaceFlags() << rfReplaceAll);
/*************************************************/
and this one works only if the position of the string is known..
/************************************************/
AnsiString str;
for(int i = 0; i < Memo1->Lines->Count; i++) // Loop through all
lines...
{
int pos = StrToInt(txtPos->Text); // string position
int count = StrToInt(txtStellen->Text); // string length...
str = Memo1->Lines->Strings[i];
str.Delete(pos, count);
Memo1->Lines->Strings[i] = str;
}
/************************************************/
Can someone please HELP ????
Thanks in advance..
Oren
 
 

Re:Repost (no replays): How can I delete strings depending on their length in a Memo or RichEdit ??

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
You never got any replies because you never posted this particular issue to
begin with. If you did post it, then it never reached the groups correctly.
I never saw it around.
Quote
Now, I have to delete several strings that their length is
less (< ) than 5... that means ALL strings that are seperated
by a space " " or by CRLF's..
At first, I was going to suggest that you use the EM_FINDWORDBREAK message
to locate the boundaries around the individual words and then manipulate the
SelStart, SelLength, and SelText properties to remove the words that are too
short. Howeveer, during testing, although it worked fairly well, I found
that EM_FINDWORDBREAK was ignoring the line breaks no matter what parameters
I gave it, so it did not find all of the matches correctly.
EM_FINDWORDBREAK also had trouble with the "," and "-" characters, which
became a burden to handle individually.
So, I'm going to suggest that you use the STL's std::string class instead.
It has find_first_of() and find_first_not_of() methods that are well suited
for the kind of searching that you are asking for. The following code
worked fine for me with the example you posted earlier:
std::string str = RichEdit1->Text.c_str();
std::string separators = " \r\n";
int n = str.length();
int start, stop;
start = str.find_first_not_of(separators);
while( (start>= 0) && (start < n) )
{
stop = str.find_first_of(separators, start);
if( (stop < 0) || (stop>n) ) stop = n;
if( (stop-start) < 5 )
{
if( (stop < n) && (str[stop] == ' ') ) ++stop;
str.erase(start, stop-start);
n -= (stop-start);
start = str.find_first_not_of(separators, start);
}
else
start = str.find_first_not_of(separators, stop+1);
}
RichEdit1->Text = str.c_str();
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
 

Re:Repost (no replays): How can I delete strings depending on their length in a Memo or RichEdit ??

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
tmp->CommaText = s;
That won't work, the words are not comma-delimited, and also there are
actual commas in the original text. You're probably thinking of
DelimitedText instead, if you are using BCB6. However, that would not take
line breaks into account correctly, either.
Quote
for( int x = 0; x < tmp->Count; ++x )
if( tmp->Strings[ x ].Length()>4 )
FinalList->Add( tmp->Strings[ x ] );
You're not preserving any of the spacing between the words. Oren did not
specify whether that was important or not, but given the odd spacing of the
original text to begin with, I would imagine that the spaces have some
significance.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
 

{smallsort}

Re:Repost (no replays): How can I delete strings depending on their length in a Memo or RichEdit ??

Once again Remy, thanks alot for the help :-)
Oren