Topic: AnsiStrings, How to get length?


Author: "Curious George" <george@tophat.com>
Date: 1997/03/12
Raw View
Hey Master Programmers,

I am an old C programmer that converted to Delphi, and now back to C++ via
Borland C++Builder.  I have been spoiled by some of Delphi's neat features,
but am happy to be back in my favorite language! (and I'm sure I'll be
spoiled by this terrific new C++Builder).

My problem is the new "AnsiString" string object in C++Builder.  I am used
to looking at C strings as character arrays with a \0 NULL terminator.
That is available in C++Builder like it should be, but some excellent
functionality is in the new AnsiString object.  They seem much like the
Pascal TString.

(1.) Question is, how do you find the length of a AnsiString?  I can find
no function that will work with AnsiStrings to show length.  In Delphi the
first byte of a Pascal TString contained the length of the string.  That
doesn't seem to apply to a C++Builder TString.  I've tried the standard C
length type functions like strlen(), but they are designed for C style null
terminated character arrays.

(2.)  Is there a function that converts from an AnsiString to a Char Array?
 I am attempting to write one, but can't find the length of the AnsiString
so that I can parse it in a For loop and convert it to a char array.

Thanks in advance for your help!

Darrell Young
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/03/12
Raw View
"Curious George" <george@tophat.com> writes:

>My problem is the new "AnsiString" string object in C++Builder.

The ANSI/ISO C++ committee draft does not define any type called
`AnsiString'.  Hence, despite the name, the class is not standard,
and so you will have to look at the documentation for your implementation.

The ANSI/ISO C++ committee draft does however define a type `string';
you can find the length of an ANSI/ISO `string' using the length()
member function, and you can get a C-style pointer to a null-terminated
array of bytes using the `c_str()' member function.

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]