Lua
C++
Edit

Strings

Strings in Ultra Engine are handled with two classes. The String class defines a narrow string and is derived from both the std::string and Object classes. The WString class defines a wide string and is derived from both the std::wstring and Object classes. It is preferable to use the WString class, as this will handle all characters of all languages.

Constructors

Both string classes can be created from a string literal:

String s = "Hello!";
WString ws = "Hello!";

A wide string literal should be used for unicode strings:

WString ws = L"您好";

Common numeric data types can be converted to a string with a constructor:

String s1 = String(2);// integer to string conversion
String s2 = String(2.43434f);// float to string conversion
WString s3 = WString(2343432.343243);// double float to wide string conversion

String Conversion

Narrow to wide string conversion is automatic:

String s = "Hello!";
WString ws = s;

Because wide to narrow string conversion can involve a possible loss of data, the WString::ToString method must be explicitly called:

WString ws = "Hello!";
String s = ws.ToString();

Strings can also be converted to integer or floating point values:

int n = String("465").ToInt();
float f = String("3.14").ToFloat();
Copyright © 2024 Ultra Software.
All rights reserved.