System.AnsiStringT

From RAD Studio API Documentation
Jump to: navigation, search

C++

class RTL_DELPHIRETURN AnsiStringT : public AnsiStringBase

Properties

Type Visibility Source Unit Parent
class public dstring.h System System

Description

AnsiStringT is the C++ analog for the Delphi long string type.

AnsiStringT provides a place for methods and members that are common to all instantiations of the template class AnsiStringT<CodePage>. Besides, it is a template class used when handling a Delphi AnsiString that has a code page specified with it, holding code for each specific code page.

Note: Please review AnsiString to check more information about AnsiString's functionality.

Despite its name, AnsiStringT is not restricted to the ANSI character set and can use any character set supported by the current locale definition, including multibyte or Unicode character sets.

Delphi uses several string types, one of which is commonly known as AnsiString. Support for this type includes the following features:

  • Strings can be as large as the available memory.
  • Efficient use of memory is ensured through shared references.
  • Routines and operators evaluate strings based on the current locale.

Considerations

Consider the following notes when using AnsiStringT:

  • AnsiString itself is a typedef equivalent to AnsiStringT<CodePage>. In C++ you can use AnsiStringT directly or you can create a n alias, as in Delphi.
  • AnsiStringT variables that have not been assigned an initial value contain a zero-length string.
  • To use the C++ streaming operators (<< and >>) with AnsiStringT, you must include iostream before including system.hpp or use AnsiStringT::c_str() to return the internal string representation.
    The following example demonstrates the usage of AnsiString with stream operators in both ways:
Option 1 Option 2
#include <System.hpp>

int main() {
   AnsiString HelloStr = "hello";
   std::cout << HelloStr.c_str();
}
#include <iostream>
#include <System.hpp>
int main() {
   AnsiString HelloStr = "hello";
   std::cout << HelloStr.c_str();
}
Note: Delphi also supports AnsiString, but implements it as a primitive type rather than a class. By default, variables declared as type String are UnicodeString.

See Also