String

String class

String class used across the library. Is a substitute for C# System.String when translating code. For optimization reasons, isn’t considered an Object subclass. This type should be allocated on stack and passed to functions by value or by reference. Never use System::SmartPtr class to manage objects of this type.

class String

Methods

MethodDescription
const UChar * begin() constReturns pointer to the beginning of actual string buffer. Never reallocates anything. Doesn’t guarantee buffer to be null-terminated.
String Clone() constCreates a copy of current string.
static int Compare(const String&, int, const String&, int, int, bool)Less-equal-greater-compares two substrings.
static int Compare(const String&, int, const String&, int, int, bool, const SharedPtr<System::Globalization::CultureInfo>&)Less-equal-greater-compares two substrings.
static int Compare(const String&, const String&, System::StringComparison)Less-equal-greater-compares two strings.
static int Compare(const String&, int, const String&, int, int, System::StringComparison)Less-equal-greater-compares two strings.
static int Compare(const String&, const String&, bool)Less-equal-greater-compares two strings.
static int Compare(const String&, const String&, bool, const SharedPtr<System::Globalization::CultureInfo>&)Less-equal-greater-compares two strings.
static int CompareOrdinal(const String&, const String&)Less-equal-greater-compares two strings using ordinal mode.
static int CompareOrdinal(const String&, int, const String&, int, int)Less-equal-greater-compares two strings using ordinal mode.
int CompareTo(const String&) constCompares two strings in ’less-equals-more’ style. Uses current culture.
static String Concat(const ArrayPtr<String>&)Concatenates strings.
static String Concat(const String&, const String&)Concatenates strings.
static String Concat(const String&, const String&, const String&)Concatenates strings.
static String Concat(const String&, const String&, const String&, const String&)Concatenates strings.
bool Contains(const String&) constChecks if str is a substring of current string.
static String Copy(const String&)Creates string copy.
void CopyTo(int, const ArrayPtr<char_t>&, int, int) constCopies string characters into existing array elements. No resize is being done.
const UChar * end() constReturns pointer to the end of actual string buffer. Never reallocates anything. Doesn’t guarantee buffer to be null-terminated.
bool EndsWith(const String&) constChecks if string ends with specified substring.
bool EndsWith(const String&, System::StringComparison) constChecks if string ends with specified substring.
bool EndsWith(const String&, bool, const SharedPtr<System::Globalization::CultureInfo>&) constChecks if string ends with specified substring.
bool Equals(const String&, System::StringComparison) constString equality comparison. Several modes provided by StringComparison enumeration are supported.
bool Equals(const String&) constString equality comparison. Uses System::StringComparison::Ordinal comparison mode.
static bool Equals(const String&, const String&)Equal-compares two strings using Ordial comparison mode.
static bool Equals(const String&, const String&, System::StringComparison)Equal-compares two strings.
int FastToAscii(char, int) constTries to convert a String to an ASCII string.
static String Format(const SharedPtr<IFormatProvider>&, const String&, const Args&…)Formats string in C# style.
static String Format(std::nullptr_t, const String&, const Args&…)Formats string in C# style.
static String Format(std::nullptr_t, const char16_t(&), const Args&…)Formats string in C# style.
static String Format(const String&, const Args&…)Formats string in C# style.
static String Format(const String&, const System::ArrayPtr<T>&)Formats string in C# style.
static String FromAscii(const char *)Creates String from ASCII string.
static String FromAscii(const char *, int)Creates String from ASCII string.
static String FromAscii(const std::string&)Creates String from ASCII string.
static String FromUtf16(const std::u16string&)Creates String from utf16 string.
static String FromUtf32(const uint32_t *, int32_t)Creates String from utf32 string.
static String FromUtf8(const char *)Creates String from utf8 string.
static String FromUtf8(const char *, int)Creates String from utf8 string.
static String FromUtf8(const uint8_t *)Creates String from utf8 string.
static String FromUtf8(const std::string&)Creates String from utf8 string.
static String FromWCS(const std::wstring&)Creates String from widestring.
int get_Length() constGets string length.
int GetHashCode() constHashes contained string. Implemented in ICU, doesn’t match hashes in C#.
int IndexOf(const String&, System::StringComparison) constSubstring forward lookup.
int IndexOf(char_t, int) constCharacter forward lookup.
int IndexOf(char_t, int, int) constCharacter forward lookup in substring.
int IndexOf(const String&, int) constSubstring forward lookup.
int IndexOf(const String&, int, System::StringComparison) constSubstring forward lookup.
int IndexOf(const String&, int, int, System::StringComparison) constSubstring forward lookup.
int IndexOf(const String&, int, int) constSubstring forward lookup.
int IndexOfAny(char_t, int) constCharacter forward lookup.
int IndexOfAny(const String&, int) constConsequently looks for all characters of str in this. If first character is found, its position is returned, otherwise looks for the second one and so on.
int IndexOfAny(const ArrayPtr<char_t>&) constLooks for any of passed characters through the whole string. Compares first string character to all characters in anyOf, then compares second one and so on. Returns index of the first one matching any of the target characters.
int IndexOfAny(const ArrayPtr<char_t>&, int32_t) constLooks for any of passed characters through substring. Compares first string character to all characters in anyOf, then compares second one and so on. Returns index of the first one matching any of the target characters.
int IndexOfAny(const ArrayPtr<char_t>&, int32_t, int32_t) constLooks for any of passed characters through substring. Compares first string character to all characters in anyOf, then compares second one and so on. Returns index of the first one matching any of the target characters.
String Insert(int, const String&) constInserts substring at specified position.
bool Is(const System::TypeInfo&) constChecks if string object is of type specified by TypeInfo passed.
bool IsAsciiString() constIndicates if a String contains ASCII symbols only.
bool IsEmpty() constChecks if string is both non-null and empty.
bool IsNormalized(System::Text::NormalizationForm) constChecks if unicode string is normalized using normalization form specified.
bool IsNull() constChecks if string is considered null. String is null and only if it is constructed via String() constructor, moved, copied or assigned from null string or reset() method was called.
bool IsNullOrEmpty() constChecks if string is empty or is considered null.
static bool IsNullOrEmpty(const String&)Checks if passed string is null or empty.
static bool IsNullOrWhiteSpace(const String&)Indicates whether a specified string is null, empty, or consists only of white-space characters.
static String Join(const String&, const ArrayPtr<String>&, int, int)Joins array using string as separator.
static String Join(const String&, const System::Details::ArrayView<String>&, int, int)Joins array using string as separator.
static String Join(const String&, const SharedPtr<System::Collections::Generic::IEnumerable<String>>&)Joins array using string as separator.
static String Join(const String&, const ArrayPtr<SharedPtr<Object>>&)Joins array using string as separator.
int LastIndexOf(const String&, int) constSubstring backward lookup.
int LastIndexOf(const String&, System::StringComparison) constSubstring backward lookup.
int LastIndexOf(const String&, int, System::StringComparison) constSubstring backward lookup.
int LastIndexOf(const String&, int, int, StringComparison) constSubstring backward lookup.
int LastIndexOf(char_t) constCharacter backward lookup.
int LastIndexOf(char_t, int32_t) constCharacter backward lookup.
int LastIndexOf(char_t, int32_t, int32_t) constCharacter backward lookup.
int LastIndexOfAny(const ArrayPtr<char_t>&) constLooks for any of passed characters through whole string backwardly. Compares last string character to all characters in anyOf, then compares previous one and so on. Returns index of the first match found.
int LastIndexOfAny(const ArrayPtr<char_t>&, int32_t) constLooks for any of passed characters through substring backwardly. Compares last string character to all characters in anyOf, then compares previous one and so on. Returns index of the first match found.
int LastIndexOfAny(const ArrayPtr<char_t>&, int32_t, int32_t) constLooks for any of passed characters through substring backwardly. Compares last string character to all characters in anyOf, then compares previous one and so on. Returns index of the first match found.
String Normalize(System::Text::NormalizationForm) constNormalizes unicode string using normalization form specified.
bool operator!=(const String&) constNon-equality comparison operator.
bool operator!=(std::nullptr_t) constChecks if string is not null. Applies same logic as IsNull() call.
String operator+(const String&) constString concatenation operator.
String operator+(const T&) constString concatenation with string literal or character string pointer.
String operator+(char_t) constAdds character to the end of the string.
String operator+(int) constAdds integer value string representation to the end of the string.
String operator+(uint32_t) constAdds unsigned integer value string representation to the end of the string.
String operator+(double) constAdds floating point value string representation to the end of the string.
String operator+(int64_t) constAdds integer value string representation to the end of the string.
String operator+(const T&) constAdds reference type object string representation to the end of the string.
String operator+(const T&) constAdds reference type object string representation to the end of the string.
String operator+(T) constAdds boolean value string representation to the end of the string.
String& operator+=(char_t)Concatenation assignment operator.
String& operator+=(const String&)Concatenation assignment operator.
String& operator+=(double)Concatenation assignment operator.
String& operator+=(uint8_t)Concatenation assignment operator.
String& operator+=(int16_t)Concatenation assignment operator.
String& operator+=(uint16_t)Concatenation assignment operator.
String& operator+=(int32_t)Concatenation assignment operator.
String& operator+=(uint32_t)Concatenation assignment operator.
String& operator+=(int64_t)Concatenation assignment operator.
String& operator+=(uint64_t)Concatenation assignment operator.
String& operator+=(T)Concatenation assignment operator.
bool operator<(const String&) constOrder-compares strings.
String& operator=(const String&)Assignment operator.
String& operator=(String&&)Move assignment operator.
bool operator==(const String&) constEquality comparison operator.
bool operator==(std::nullptr_t) constChecks if string is null. Applies same logic as IsNull() call.
char_t operator[](int) constGets character at specified position.
String PadLeft(int, char_t) constAdds padding on the left of original string.
String PadRight(int, char_t) constAdds padding on the right of original string.
reverse_iterator rbegin() constReturns reverse iterator to the last character (if any) of actual string buffer.
String Remove(int32_t, int32_t) constExtracts everything but substring from current string.
reverse_iterator rend() constReturns reverse iterator to the before first character (if any) of actual string buffer.
String Replace(char_t, char_t) constReplaces all occurrences of character in the string.
String Replace(const String&, const String&) constReplaces all occurrences of lookup in this string.
String& reset()Sets string to null. Is analogous to ‘string_variable_name = null’ in C#.
String& SetCharAt(int, char_t)Sets character at specified position.
ArrayPtr<String> Split(char_t, StringSplitOptions) constSplits string by character.
ArrayPtr<String> Split(char_t, int32_t, StringSplitOptions) constSplits string by character.
ArrayPtr<String> Split(char_t, char_t, StringSplitOptions) constSplits string by one of two characters.
ArrayPtr<String> Split(const ArrayPtr<char_t>&, StringSplitOptions) constSplits string by one of characters specified.
ArrayPtr<String> Split(const ArrayPtr<char_t>&, int32_t, StringSplitOptions) constSplits string by one of characters specified.
ArrayPtr<String> Split(const String&, StringSplitOptions) constSplits string by substring.
ArrayPtr<String> Split(const String&, int, StringSplitOptions) constSplits string by substring.
ArrayPtr<String> Split(const ArrayPtr<String>&, StringSplitOptions) constSplits string by substring.
ArrayPtr<String> Split(const ArrayPtr<String>&, int, StringSplitOptions) constSplits string by substring. Currently, only supports separators array of zero or one elements.
bool StartsWith(const String&) constChecks if string begins with specified substring.
bool StartsWith(const String&, System::StringComparison) constChecks if string begins with specified substring.
bool StartsWith(const String&, bool, const SharedPtr<System::Globalization::CultureInfo>&) constChecks if string begins with specified substring.
String()Default constructor. Creates string object which is considered null.
String(T&, typename std::enable_if<IsStringLiteral<T, char16_t>::value>::type *)Constructs string based on string literal. Considers literal a null-terminated string, calculates target string length based on literal size.
String(const T&, typename std::enable_if<IsStringPointer<T, char16_t>::value>::type *)Constructs string based on character string pointer. Treats pointed string as null-terminated, calculates target string length based on null character.
explicit String(T&, typename std::enable_if<IsStringLiteral<T, char>::value>::type *)Constructs string based on string literal. Considers literal a null-terminated string in UTF8, calculates target string length based on literal size.
explicit String(const T&, typename std::enable_if<IsStringPointer<T, char>::value>::type *)Constructs string based on character string pointer. Treats pointed string as null-terminated in UTF8, calculates target string length based on null character.
String(const char16_t *, int)Constructs string from character string pointer and explicit length.
String(const char *, int)Constructs string from character string pointer and explicit length.
String(const char16_t *, int, int)Constructs string from character string pointer from starting position using length.
explicit String(const char16_t, int)Fill constructor.
String(const T&, typename std::enable_if<std::is_same<T, std::nullptr_t>::value>::type *)Nullptr constructor. Declared as template to resolve priorities with other template constructors.
explicit String(T&, typename std::enable_if<IsStringLiteral<T, wchar_t>::value>::type *)Constructs string based on widestring literal. Considers literal a null-terminated string, calculates target string length based on literal size. Conversion from wchar_t is time-consuming on some platforms, so no implicit conversions are allowed.
explicit String(const T&, typename std::enable_if<IsStringPointer<T, wchar_t>::value>::type *)Constructs string based on widecharacter string pointer. Treats pointed string as null-terminated, calculates target string length based on null character. Conversion from wchar_t is time-consuming on some platforms, so no implicit conversions are allowed.
explicit String(const wchar_t *, int)Constructs string from widecharacter string pointer and explicit length. Conversion from wchar_t is time-consuming on some platforms, so no implicit conversions are allowed.
explicit String(const wchar_t, int)Fill constructor. Conversion from wchar_t is time-consuming on some platforms, so no implicit conversions are allowed.
String(const String&)Copy constructor.
String(String&&)Move constructor.
String(const ArrayPtr<char16_t>&)Converts whole character array to string.
String(const ArrayPtr<char16_t>&, int, int)Converts character array subrange to string. If parameters are out of array bounds, empty string is constructed.
explicit String(const codeporting_icu::UnicodeString&)Wraps UnicodeString into String.
explicit String(codeporting_icu::UnicodeString&&)Move constructor.
explicit String(const std::wstring&)Creates String from widestring.
explicit String(const std::u16string&)Creates String from utf16 string.
explicit String(const std::string&)Creates String from std::string string presented in format UTF-8.
explicit String(const std::u32string&)Creates String from std::u32string string.
String Substring(int32_t) constExtracts substring.
String Substring(int32_t, int32_t) constExtracts substring.
std::string ToAsciiString() constConverts string to std::string. Uses ASCII encoding.
ArrayPtr<uint8_t> ToByteArray(int32_t, int32_t, bool) constConverts string or substring to array of bytes.
ArrayPtr<char_t> ToCharArray(int32_t, int32_t) constConverts string or substring to array of characters.
String ToLower() constConverts all string’s characters to lower case.
String ToLower(const SharedPtr<System::Globalization::CultureInfo>&) constConverts all string’s characters to lower case using specific culture.
String ToLowerInvariant() constConverts all string’s characters to lower case using invariant culture.
String ToString() constWrapper for handling String class in contexts where ToString() is being called on value type objects.
String ToString(const SharedPtr<IFormatProvider>&) constWrapper for handling String class in contexts where ToString() is being called on value type objects.
std::u16string ToU16Str() constConverts string to std::u16string.
std::u32string ToU32Str() constConverts string to std::u32string.
String ToUpper() constConverts all string’s characters to upper case.
String ToUpper(const SharedPtr<System::Globalization::CultureInfo>&) constConverts all string’s characters to upper case using specific culture.
String ToUpperInvariant() constConverts all string’s characters to upper case using invariant culture.
std::string ToUtf8String() constConverts string to std::string. Uses UTF-8 encoding.
std::wstring ToWCS() constConverts string to std::wstring.
String Trim() constRemoves all whitespace characters from both beginning and end of the string.
String Trim(char_t) constRemoves all occurrences of passed character from both beginning and end of the string.
String Trim(const String&) constRemoves all occurrences of passed characters from both beginning and end of the string.
String Trim(const ArrayPtr<char_t>&) constRemoves all occurrences of passed characters from both beginning and end of the string.
String TrimEnd() constRemoves all whitespace characters from end of the string.
String TrimEnd(char_t) constRemoves all occurrences of passed character from end of the string.
String TrimEnd(const String&) constRemoves all occurrences of passed characters from end of the string.
String TrimEnd(const ArrayPtr<char_t>&) constRemoves all occurrences of passed characters from end of the string.
String TrimStart() constRemoves all whitespace characters from beginning of the string.
String TrimStart(char_t) constRemoves all occurrences of passed character from beginning of the string.
String TrimStart(const String&) constRemoves all occurrences of passed characters from beginning of the string.
String TrimStart(const ArrayPtr<char_t>&) constRemoves all occurrences of passed characters from beginning of the string.
const UChar * u_str() constReturns ICU-styled null-terminated buffer. May reallocate the string.
~String()Destructor.

Fields

FieldDescription
static EmptyEmpty string.
static NullNull string.

Typedefs

TypedefDescription
reverse_iteratorReverse iterator type.

Remarks

#include "system/string.h"
#include <iostream>

int main()
{
  // Construct a string from the array of characters and print it.
  const auto chars = {u'h', u'e', u'l', u'l', u'o'};
  const System::String string1(chars);
  std::cout << string1 << std::endl;

  // Construct a string from the array of bytes and print it.
  const uint8_t bytes[] = {0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0};
  const auto string2 = System::String::FromUtf8(bytes);
  std::cout << string2 << std::endl;

  // Trim the string below and print it.
  const System::String string3(u"   This string contains whitespaces in the beginning and at the end.   ");
  std::cout << '"' << string3.Trim() << '"' << std::endl;

  // Print the number of words in the .
  std::cout << "Number of words: " << string3.Trim().Split(' ')->get_Length() << std::endl;

  return 0;
}
/*
This code example produces the following output:
hello
world
"This string contains whitespaces in the beginning and at the end."
Number of words: 11
*/

See Also