System::String class

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
begin() constReturns pointer to the beginning of actual string buffer. Never reallocates anything. Doesn’t guarantee buffer to be null-terminated.
Clone() constCreates a copy of current string.
static Compare(const String&, int, const String&, int, int, bool)Less-equal-greater-compares two substrings.
static Compare(const String&, int, const String&, int, int, bool, const SharedPtr<System::Globalization::CultureInfo>&)Less-equal-greater-compares two substrings.
static Compare(const String&, const String&, System::StringComparison)Less-equal-greater-compares two strings.
static Compare(const String&, int, const String&, int, int, System::StringComparison)Less-equal-greater-compares two strings.
static Compare(const String&, const String&, bool)Less-equal-greater-compares two strings.
static Compare(const String&, const String&, bool, const SharedPtr<System::Globalization::CultureInfo>&)Less-equal-greater-compares two strings.
static CompareOrdinal(const String&, const String&)Less-equal-greater-compares two strings using ordinal mode.
static CompareOrdinal(const String&, int, const String&, int, int)Less-equal-greater-compares two strings using ordinal mode.
CompareTo(const String&) constCompares two strings in ’less-equals-more’ style. Uses current culture.
static Concat(const ArrayPtr<String>&)Concatenates strings.
static Concat(const String&, const String&)Concatenates strings.
static Concat(const String&, const String&, const String&)Concatenates strings.
static Concat(const String&, const String&, const String&, const String&)Concatenates strings.
Contains(const String&) constChecks if str is a substring of current string.
static Copy(const String&)Creates string copy.
CopyTo(int, const ArrayPtr<char_t>&, int, int) constCopies string characters into existing array elements. No resize is being done.
end() constReturns pointer to the end of actual string buffer. Never reallocates anything. Doesn’t guarantee buffer to be null-terminated.
EndsWith(const String&) constChecks if string ends with specified substring.
EndsWith(const String&, System::StringComparison) constChecks if string ends with specified substring.
EndsWith(const String&, bool, const SharedPtr<System::Globalization::CultureInfo>&) constChecks if string ends with specified substring.
Equals(const String&, System::StringComparison) constString equality comparison. Several modes provided by StringComparison enumeration are supported.
Equals(const String&) constString equality comparison. Uses System::StringComparison::Ordinal comparison mode.
static Equals(const String&, const String&)Equal-compares two strings using Ordial comparison mode.
static Equals(const String&, const String&, System::StringComparison)Equal-compares two strings.
FastToAscii(char, int) constTries to convert a String to an ASCII string.
static Format(const SharedPtr<IFormatProvider>&, const String&, const Args&…)Formats string in C# style.
static Format(std::nullptr_t, const String&, const Args&…)Formats string in C# style.
static Format(std::nullptr_t, const char16_t(&), const Args&…)Formats string in C# style.
static Format(const String&, const Args&…)Formats string in C# style.
static Format(const String&, const System::ArrayPtr<T>&)Formats string in C# style.
static FromAscii(const char *)Creates String from ASCII string.
static FromAscii(const char *, int)Creates String from ASCII string.
static FromAscii(const std::string&)Creates String from ASCII string.
static FromUtf16(const std::u16string&)Creates String from utf16 string.
static FromUtf32(const uint32_t *, int32_t)Creates String from utf32 string.
static FromUtf8(const char *)Creates String from utf8 string.
static FromUtf8(const char *, int)Creates String from utf8 string.
static FromUtf8(const uint8_t *)Creates String from utf8 string.
static FromUtf8(const std::string&)Creates String from utf8 string.
static FromWCS(const std::wstring&)Creates String from widestring.
get_Length() constGets string length.
GetHashCode() constHashes contained string. Implemented in ICU, doesn’t match hashes in C#.
IndexOf(const String&, System::StringComparison) constSubstring forward lookup.
IndexOf(char_t, int) constCharacter forward lookup.
IndexOf(char_t, int, int) constCharacter forward lookup in substring.
IndexOf(const String&, int) constSubstring forward lookup.
IndexOf(const String&, int, System::StringComparison) constSubstring forward lookup.
IndexOf(const String&, int, int, System::StringComparison) constSubstring forward lookup.
IndexOf(const String&, int, int) constSubstring forward lookup.
IndexOfAny(char_t, int) constCharacter forward lookup.
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.
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.
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.
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.
Insert(int, const String&) constInserts substring at specified position.
Is(const System::TypeInfo&) constChecks if string object is of type specified by TypeInfo passed.
IsAsciiString() constIndicates if a String contains ASCII symbols only.
IsEmpty() constChecks if string is both non-null and empty.
IsNormalized(System::Text::NormalizationForm) constChecks if unicode string is normalized using normalization form specified.
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.
IsNullOrEmpty() constChecks if string is empty or is considered null.
static IsNullOrEmpty(const String&)Checks if passed string is null or empty.
static IsNullOrWhiteSpace(const String&)Indicates whether a specified string is null, empty, or consists only of white-space characters.
static Join(const String&, const ArrayPtr<String>&, int, int)Joins array using string as separator.
static Join(const String&, const System::Details::ArrayView<String>&, int, int)Joins array using string as separator.
static Join(const String&, const SharedPtr<System::Collections::Generic::IEnumerable<String>>&)Joins array using string as separator.
static Join(const String&, const ArrayPtr<SharedPtr<Object>>&)Joins array using string as separator.
LastIndexOf(const String&, int) constSubstring backward lookup.
LastIndexOf(const String&, System::StringComparison) constSubstring backward lookup.
LastIndexOf(const String&, int, System::StringComparison) constSubstring backward lookup.
LastIndexOf(const String&, int, int, StringComparison) constSubstring backward lookup.
LastIndexOf(char_t) constCharacter backward lookup.
LastIndexOf(char_t, int32_t) constCharacter backward lookup.
LastIndexOf(char_t, int32_t, int32_t) constCharacter backward lookup.
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.
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.
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.
Normalize(System::Text::NormalizationForm) constNormalizes unicode string using normalization form specified.
operator!=(const String&) constNon-equality comparison operator.
operator!=(std::nullptr_t) constChecks if string is not null. Applies same logic as IsNull() call.
operator+(const String&) constString concatenation operator.
operator+(const T&) constString concatenation with string literal or character string pointer.
operator+(char_t) constAdds character to the end of the string.
operator+(int) constAdds integer value string representation to the end of the string.
operator+(uint32_t) constAdds unsigned integer value string representation to the end of the string.
operator+(double) constAdds floating point value string representation to the end of the string.
operator+(int64_t) constAdds integer value string representation to the end of the string.
operator+(const T&) constAdds reference type object string representation to the end of the string.
operator+(const T&) constAdds reference type object string representation to the end of the string.
operator+(T) constAdds boolean value string representation to the end of the string.
operator+=(char_t)Concatenation assignment operator.
operator+=(const String&)Concatenation assignment operator.
operator+=(double)Concatenation assignment operator.
operator+=(uint8_t)Concatenation assignment operator.
operator+=(int16_t)Concatenation assignment operator.
operator+=(uint16_t)Concatenation assignment operator.
operator+=(int32_t)Concatenation assignment operator.
operator+=(uint32_t)Concatenation assignment operator.
operator+=(int64_t)Concatenation assignment operator.
operator+=(uint64_t)Concatenation assignment operator.
operator+=(T)Concatenation assignment operator.
operator<(const String&) constOrder-compares strings.
operator=(const String&)Assignment operator.
operator=(String&&)Move assignment operator.
operator==(const String&) constEquality comparison operator.
operator==(std::nullptr_t) constChecks if string is null. Applies same logic as IsNull() call.
operator[](int) constGets character at specified position.
PadLeft(int, char_t) constAdds padding on the left of original string.
PadRight(int, char_t) constAdds padding on the right of original string.
rbegin() constReturns reverse iterator to the last character (if any) of actual string buffer.
Remove(int32_t, int32_t) constExtracts everything but substring from current string.
rend() constReturns reverse iterator to the before first character (if any) of actual string buffer.
Replace(char_t, char_t) constReplaces all occurrences of character in the string.
Replace(const String&, const String&) constReplaces all occurrences of lookup in this string.
reset()Sets string to null. Is analogous to ‘string_variable_name = null’ in C#.
SetCharAt(int, char_t)Sets character at specified position.
Split(char_t, StringSplitOptions) constSplits string by character.
Split(char_t, int32_t, StringSplitOptions) constSplits string by character.
Split(char_t, char_t, StringSplitOptions) constSplits string by one of two characters.
Split(const ArrayPtr<char_t>&, StringSplitOptions) constSplits string by one of characters specified.
Split(const ArrayPtr<char_t>&, int32_t, StringSplitOptions) constSplits string by one of characters specified.
Split(const String&, StringSplitOptions) constSplits string by substring.
Split(const String&, int, StringSplitOptions) constSplits string by substring.
Split(const ArrayPtr<String>&, StringSplitOptions) constSplits string by substring.
Split(const ArrayPtr<String>&, int, StringSplitOptions) constSplits string by substring. Currently, only supports separators array of zero or one elements.
StartsWith(const String&) constChecks if string begins with specified substring.
StartsWith(const String&, System::StringComparison) constChecks if string begins with specified substring.
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.
Substring(int32_t) constExtracts substring.
Substring(int32_t, int32_t) constExtracts substring.
ToAsciiString() constConverts string to std::string. Uses ASCII encoding.
ToByteArray(int32_t, int32_t, bool) constConverts string or substring to array of bytes.
ToCharArray(int32_t, int32_t) constConverts string or substring to array of characters.
ToLower() constConverts all string’s characters to lower case.
ToLower(const SharedPtr<System::Globalization::CultureInfo>&) constConverts all string’s characters to lower case using specific culture.
ToLowerInvariant() constConverts all string’s characters to lower case using invariant culture.
ToString() constWrapper for handling String class in contexts where ToString() is being called on value type objects.
ToString(const SharedPtr<IFormatProvider>&) constWrapper for handling String class in contexts where ToString() is being called on value type objects.
ToU16Str() constConverts string to std::u16string.
ToU32Str() constConverts string to std::u32string.
ToUpper() constConverts all string’s characters to upper case.
ToUpper(const SharedPtr<System::Globalization::CultureInfo>&) constConverts all string’s characters to upper case using specific culture.
ToUpperInvariant() constConverts all string’s characters to upper case using invariant culture.
ToUtf8String() constConverts string to std::string. Uses UTF-8 encoding.
ToWCS() constConverts string to std::wstring.
Trim() constRemoves all whitespace characters from both beginning and end of the string.
Trim(char_t) constRemoves all occurrences of passed character from both beginning and end of the string.
Trim(const String&) constRemoves all occurrences of passed characters from both beginning and end of the string.
Trim(const ArrayPtr<char_t>&) constRemoves all occurrences of passed characters from both beginning and end of the string.
TrimEnd() constRemoves all whitespace characters from end of the string.
TrimEnd(char_t) constRemoves all occurrences of passed character from end of the string.
TrimEnd(const String&) constRemoves all occurrences of passed characters from end of the string.
TrimEnd(const ArrayPtr<char_t>&) constRemoves all occurrences of passed characters from end of the string.
TrimStart() constRemoves all whitespace characters from beginning of the string.
TrimStart(char_t) constRemoves all occurrences of passed character from beginning of the string.
TrimStart(const String&) constRemoves all occurrences of passed characters from beginning of the string.
TrimStart(const ArrayPtr<char_t>&) constRemoves all occurrences of passed characters from beginning of the string.
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