Board index » cppbuilder » AnsiString - Undefined Functions

AnsiString - Undefined Functions


2006-03-07 05:02:44 AM
cppbuilder29
I am having no trouble with the AnsiString Methods:
But there doesn't seem to be a Replace method.
Why not? I had to write my own...
However, I can't get many of the AnsiString Functions to work:
AnsiString a = "abcdefghijklmnopqrstuvwxyz";
AnsiString A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
AnsiString spaces = " Now is the time men to come. ";
void doit (void) {
a = AnsiUpperCase(a); // OK
A = AnsiLowerCase(A); // OK
spaces = Trim(spaces); // OK
//A = AnsiReplaceStr(A, "def", "XXX"); // nogo
//A = ReverseString(A); // nogo
//A = StringReplace(A, "def", "DEF", rfReplaceAll); // nogo
//x = AnsiResemblesText("blue", "blew"); // nogo
I have tried all the combinations of including StrUtils and
String but these seem to make no difference.
What am I forgetting to do?
Thanks, Nick
 
 

Re:AnsiString - Undefined Functions

Jonathan,
Great! Thanks.
That works.
Now I wonder about the others...
Nick
 

Re:AnsiString - Undefined Functions

Nick Gessler wrote:
Quote
//A = StringReplace(A, "def", "DEF", rfReplaceAll); // nogo
I know that for this one, you're passing a integer value instead of a set.
You need to call it like this:
// Untested
A = StringReplace( A, "def", "DEF", TReplaceFlags() << rfReplaceAll );
HTH
Jonathan
 

{smallsort}

Re:AnsiString - Undefined Functions

Thanks Remy,
How do I include or reference SysUtils?
I guess I didn't explain myself clearly.
The code begins with these declarations/definitions:
AnsiString a = "abcdefghij";
AnsiString A = "ABCDEFGHIJ";
AnsiString spaces = " This sentence has spaces. ";
bool x;
These three commands compile and work as they should:
a = AnsiUpperCase(a);
A = AnsiLowerCase(A);
spaces = Trim(spaces);
These three commands receive an immediate "Undefined Function"
error message. They will not compile. The will not run.
A = AnsiReplaceStr(A, "def", "XXX");
// after conversion to lower case
// it should make A = "abcXXXghij"
A = ReverseString(A);
// after conversion to lower case
// it should make A = "jihgfedcba"
x = AnsiResemblesText("blue", "blew");
// it should return true
The last poster corrected the syntax on this one.
It now works with his correction.
A = StringReplace(A, "def", "DEF", rfReplaceAll);
What am I doing wrong?
Nick
 

Re:AnsiString - Undefined Functions

"Nick Gessler" < XXXX@XXXXX.COM >wrote in message
Quote
I am having no trouble with the AnsiString Methods:
But there doesn't seem to be a Replace method.
That is correct.
Quote
Why not?
Because AnsiString is primarily designed to mimic the Delphi 'String' data
type, with has no methods at all. The methods that AnsiString does have are
provided for convenience, but they do not emcompass everything that the VCL
can do with strings in general. There are many more string operatons
available that are provided as separate functions instead.
Quote
I had to write my own...
The VCL has a StringReplace() function in the SysUtils unit.
Quote
However, I can't get many of the AnsiString Functions to work:
Just saying they don't work says notning about the actual problems you are
having. Always provide specific details. What exactly do you expect the
code to do? What exactly does it do instead? Are there any errors
reported?
Gambit
 

Re:AnsiString - Undefined Functions

"Nicholas Gessler" < XXXX@XXXXX.COM >wrote in message
Quote
Now I wonder about the others...
What about them? You still need to provide more specific details about what
is not actually working for you.
Gambit
 

Re:AnsiString - Undefined Functions

"Nick Gessler" < XXXX@XXXXX.COM >wrote in message
Quote

Thanks Remy,

How do I include or reference SysUtils?
#include <StrUtils.hpp>// for AnsiReplaceStr
- Dennis
 

Re:AnsiString - Undefined Functions

"Nick Gessler" < XXXX@XXXXX.COM >wrote in message
Quote
How do I include or reference SysUtils?
The same way you include any other VCL unit - use the #include statement,
ie:
#include <SysUtils.hpp>
Quote
These three commands receive an immediate "Undefined Function"
error message.
Those functions are declared in the StrUtils unit.
Next time, please read the documentation - every VCL function and class
lists the unit that it is declared in.
Gambit
 

Re:AnsiString - Undefined Functions

"Dennis Jones" < XXXX@XXXXX.COM >wrote:
Thanks Dennis.
 

Re:AnsiString - Undefined Functions

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Thanks Remy,
But I would appreciate less condescension. Dennis gave a clear
and concise answer without being obnoxious. You might learn
that lesson from him. I have taught for over 30 years and you
do NOT insult those you are trying to teach. It is disrespectful to those who are sincerely asking you for help.
This has been your attitude for years and it's time you showed
a little humility. We can't all be computer geniuses like you
and we don't have to be in order to produce something valuable for our students or for society. So how about just helping
without the elitist attitude? Frankly, this is why many of
my students won't post to these newsgroups - they don't like
the implication that they're lazy or stupid, which they are
not.
Quote
Next time, please read the documentation - every VCL function
and class lists the unit that it is declared in.
Yes, I read that, and I spent an hour or more looking through
the documentation, plus several Borland books. Nowhere
did I find any examples of how to call that unit.
There is certainly a lot of documentation, but it is
often POORLY organized and POORLY explained, and often there
is NO example given. It is VERY inconsistent - you have to
admit that.
Cheers, Nick
 

Re:AnsiString - Undefined Functions

"Nick Gessler" < XXXX@XXXXX.COM >wrote:
Quote
But I would appreciate less condescension.
I am sure Remy didn't mean to offend. He is just so very used to
using VCL that he couldn't imagine anymore that someone reading
about the appropriate Unit couldn't guess that a Unit is
something you use #include for (and as it's Delphi even have to
add .hpp instead of .h).
Yes, he sounded a bit gruff, but he usually doesn't and others
don't either. I think you are exaggerating here and I am really
surprised that your students avoid posting for that reason.
Encourage them to post (but also encourage them to google first
;-)
Sometimes answers sound kinda rude, especially when they query
the route that a poster indends to follow. But with advanced
knowledge this makes often sense and it's good that alternatives
are shown. My advice: always picture the other one as a friendly
person who wants to help and nothing more.
Last: I like BCB's help. It is not perfect, especially not at
the point where you stumbled: I always wondered why help pages
mention "Unit StrUtils" instead of "#include <StrUtils.hpp>and
I often missed a page which simply lists all available String
functions. But in general it is a good help to me.
 

Re:AnsiString - Undefined Functions

All very good points... And I do appreciate Remy's help
as well as that of others who take the time to post here.
I suppose it's like having a class of some thousand students,
none of whom one's met, dealing with them from afar... It
is difficult to give advice with short ASCII text.
Anyway, I apologize to Remy if he has taken offense at my
comments. He too has provided me with invaluable information.
Cheers, Nick
 

Re:AnsiString - Undefined Functions

"Nick Gessler" < XXXX@XXXXX.COM >writes:
Quote
But I would appreciate less condescension. Dennis gave a clear and
concise answer without being obnoxious. You might learn that lesson
from him. I have taught for over 30 years and you do NOT insult
those you are trying to teach. It is disrespectful to those who are
sincerely asking you for help.
Please realize that the "tone" is often lost in email and newsgroup
postings. Also, we're here as peers to help get a job done, not to be
in a teacher/student relationship, and sometimes short answers are
sufficient.
Being pointed toward how to solve the problem yourself can have the
feeling of rudeness or uncaring, but it can also be the most valuable
thing one learns. As you said, you spent over an hour looking in the
wrong places...
--
Chris (TeamB);
 

Re:AnsiString - Undefined Functions

Hi
Nick Gessler a écrit:
Quote
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:

Thanks Remy,

But I would appreciate less condescension.
I have never found Remy's tone condescending or unpleasant,
(in spite of all he knows) and he saved me more than once.
He goes straight to the point (without any frill), and I appreciate.
Michel.
 

Re:AnsiString - Undefined Functions

The man responded in text. He took his own, unpaid time, stolen from his
normal activities to try to help. He wrote such that his reply is more
general than the specific problem so that others who might read the message
in search for answers to their problems might also benefit.
For that you dump on him, reading into the text of what he wrote, claiming
that he is obnoxious and condescending.
You are self-described as having taught for 30 years. After less than one
year as a teacher you should know better and you have thirty times that.
Shame on you.
. Ed
Quote
Nick Gessler wrote in message
news:440d343f$ XXXX@XXXXX.COM ...

Thanks Remy,

But I would appreciate less condescension. Dennis gave a clear
and concise answer without being obnoxious. You might learn
that lesson from him. I have taught for over 30 years and you
do NOT insult those you are trying to teach. It is disrespectful to those
who are sincerely asking you for help.
This has been your attitude for years and it's time you showed
a little humility. We can't all be computer geniuses like you
and we don't have to be in order to produce something valuable for our
students or for society. So how about just helping
without the elitist attitude? Frankly, this is why many of
my students won't post to these newsgroups - they don't like
the implication that they're lazy or stupid, which they are
not.

>Next time, please read the documentation - every VCL function
>and class lists the unit that it is declared in.

Yes, I read that, and I spent an hour or more looking through
the documentation, plus several Borland books. Nowhere
did I find any examples of how to call that unit.
There is certainly a lot of documentation, but it is
often POORLY organized and POORLY explained, and often there
is NO example given. It is VERY inconsistent - you have to
admit that.