TGUI  0.8.6
tgui::String Class Reference

Wrapper class to store strings. More...

#include <TGUI/String.hpp>

Public Member Functions

int toInt (int defaultValue=0) const
 Converts the string to an integer. More...
 
float toFloat (float defaultValue=0) const
 Converts the string to a float. More...
 
String trim () const
 Returns a string with the whitespace at the start and end of this string removed. More...
 
String toLower () const
 Converts the ASCII characters in the string to lowercase. More...
 
String toUpper () const
 Converts the ASCII characters in the string to uppercase. More...
 

Detailed Description

Wrapper class to store strings.

A constructor and conversion operator are provided for sf::String to easily convert between sf::String and tgui::String.

The interface is similar to std::basic_string, but functions accept char, wchar_t, char8_t, char16_t and char32_t. Some extra helper functions are also provided to e.g. convert the string to an integer or float or to lowercase.

Note that when converting to std::string, an UTF-8 encoded string will be returned, even by the asAnsiString function. This is done to be able to use UTF-8 without c++20 support (the asUtf8 function always returns an std::u8string). Similarly, when passing an std::string or const char* to this class, the encoding is assumed to be UTF-8.

Data is stored in UTF-32, so any parameter or operator using a different encoding will have to convert the string internally and may be slightly slower than the variants that use UTF-32.

Member Function Documentation

◆ toFloat()

float tgui::String::toFloat ( float  defaultValue = 0) const

Converts the string to a float.

Parameters
defaultValueValue to return if conversion fails

Returns the float value or defaultValue if the string didn't contain an float

◆ toInt()

int tgui::String::toInt ( int  defaultValue = 0) const

Converts the string to an integer.

Parameters
defaultValueValue to return if conversion fails

Returns the integer value or defaultValue if the string didn't contain a base 10 integer

◆ toLower()

String tgui::String::toLower ( ) const

Converts the ASCII characters in the string to lowercase.

Returns
Lowercase string

◆ toUpper()

String tgui::String::toUpper ( ) const

Converts the ASCII characters in the string to uppercase.

Returns
Uppercase string

◆ trim()

String tgui::String::trim ( ) const

Returns a string with the whitespace at the start and end of this string removed.

Returns
Trimmed string

The documentation for this class was generated from the following file: