GString
A built-in type for strings.
String.swift:13class GString
This is the built-in string Variant type (and the one used by GDScript). Strings may contain any number of Unicode characters, and expose methods useful for manipulating and generating strings. Strings are reference-counted and use a copy-on-write approach (every modification to a string returns a new String
), so passing them around is cheap in resources.
Some string methods have corresponding variations. Variations suffixed with n
(countn(what:from:to:)
, findn(what:from:)
, replacen(what:forwhat:)
, etc.) are case-insensitive (they make no distinction between uppercase and lowercase letters). Method variations prefixed with r
(rfind(what:from:)
, rsplit(delimiter:allowEmpty:maxsplit:)
, etc.) are reversed, and start from the end of the string, instead of the beginning.
Citizens in SwiftGodot
Conformances
protocol ContentVariantRepresentable
Some of Godot’s builtin classes use ContentType for storage. This needs to be public because it affects their initialization, but SwiftGodot users should never need to conform their types to
ContentVariantRepresentable
.protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol ExpressibleByExtendedGraphemeClusterLiteral
A type that can be initialized with a string literal containing a single extended grapheme cluster.
protocol ExpressibleByStringInterpolation
A type that can be initialized by string interpolation with a string literal that includes expressions.
protocol ExpressibleByStringLiteral
A type that can be initialized with a string literal.
protocol ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single Unicode scalar value.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol LosslessStringConvertible
A type that can be represented as a string in a lossless, unambiguous way.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Typealiases
Type members
init(
) Constructs an empty
String
(""
).init(String
) init(alreadyOwnedContent: ContentType
) init(content: ContentType
) init(from: GString
) init(from: StringName
) Constructs a new
String
from the givenStringName
.init(from: NodePath
) Constructs a new
String
from the givenNodePath
.init(stringLiteral: String
) static var godotType: Variant.GType
static let zero: ContentType
static func chr(char: Int64
) -> GString Returns a single Unicode character from the decimal
char
. You may use unicodelookup.com or unicode.org as points of reference.static func humanizeSize(Int64
) -> GString Converts
size
which represents a number of bytes into a human-readable form.static func num(number: Double, decimals: Int64
) -> GString Converts a float to a string representation of a decimal number, with the number of decimal places specified in
decimals
.static func numInt64(number: Int64, base: Int64, capitalizeHex: Bool
) -> GString Converts the given
number
to a string representation, with the givenbase
.static func numScientific(number: Double
) -> GString Converts the given
number
to a string representation, in scientific notation.static func numUint64(number: Int64, base: Int64, capitalizeHex: Bool
) -> GString Converts the given unsigned integer to a string representation, with the given
base
.static func != (lhs: GString, rhs: StringName
) -> Bool Returns
true
if both strings do not contain the same sequence of characters.static func != (lhs: GString, rhs: GString
) -> Bool Returns
true
if both strings do not contain the same sequence of characters.static func % (lhs: GString, rhs: Projection
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Quaternion
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: StringName
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: GDictionary
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Transform2D
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Transform3D
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedByteArray
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedColorArray
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedInt32Array
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedInt64Array
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedStringArray
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedFloat32Array
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedFloat64Array
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedVector2Array
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: PackedVector3Array
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: AABB
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Basis
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Color
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Plane
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Rect2
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: GArray
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Object
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Rect2i
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Signal
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Vector2
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Vector3
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Vector4
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Callable
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: NodePath
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Vector2i
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Vector3i
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Vector4i
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: GString
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Bool
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Double
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: GString, rhs: Int64
) -> GString Formats the
String
, replacing the placeholders with one or more parameters. To pass multiple parameters,right
needs to be anGArray
.static func + (lhs: GString, rhs: StringName
) -> GString Appends
right
at the end of thisString
, also known as a string concatenation.static func + (lhs: GString, rhs: GString
) -> GString Appends
right
at the end of thisString
, also known as a string concatenation.static func < (lhs: GString, rhs: GString
) -> Bool Returns
true
if the leftString
comes beforeright
in Unicode order, which roughly matches the alphabetical order. Useful for sorting.static func <= (lhs: GString, rhs: GString
) -> Bool Returns
true
if the leftString
comes beforeright
in Unicode order, which roughly matches the alphabetical order, or if both are equal.static func == (lhs: GString, rhs: StringName
) -> Bool Returns
true
if both strings contain the same sequence of characters.static func == (lhs: GString, rhs: GString
) -> Bool Returns
true
if both strings contain the same sequence of characters.static func > (lhs: GString, rhs: GString
) -> Bool Returns
true
if the leftString
comes afterright
in Unicode order, which roughly matches the alphabetical order. Useful for sorting.static func >= (lhs: GString, rhs: GString
) -> Bool Returns
true
if the leftString
comes afterright
in Unicode order, which roughly matches the alphabetical order, or if both are equal.
Instance members
var content: ContentType
var description: String
Returns a Swift string from this GString.
func beginsWith(text: GString
) -> Bool Returns
true
if the string begins with the giventext
. See alsoendsWith(text:)
.func bigrams(
) -> PackedStringArray Returns an array containing the bigrams (pairs of consecutive characters) of this string.
func binToInt(
) -> Int64 Converts the string representing a binary number into an integer. The string may optionally be prefixed with
"0b"
, and an additional-
prefix for negative numbers.func cEscape(
) -> GString Returns a copy of the string with special characters escaped using the C language standard.
func cUnescape(
) -> GString Returns a copy of the string with escaped characters replaced by their meanings. Supported escape sequences are
\'
,\"
,\\
,\a
,\b
,\f
,\n
,\r
,\t
,\v
.func capitalize(
) -> GString Changes the appearance of the string: replaces underscores (
_
) with spaces, adds spaces before uppercase letters in the middle of a word, converts all letters to lowercase, then converts the first one and each one following a space to uppercase.func casecmpTo(GString
) -> Int64 Performs a case-sensitive comparison to another string. Returns
-1
if less than,1
if greater than, or0
if equal. “Less than” and “greater than” are determined by the Unicode code points of each string, which roughly matches the alphabetical order.func contains(what: GString
) -> Bool Returns
true
if the string containswhat
. In GDScript, this corresponds to thein
operator.func count(what: GString, from: Int64, to: Int64
) -> Int64 Returns the number of occurrences of the substring
what
betweenfrom
andto
positions. Ifto
is 0, the search continues until the end of the string.func countn(what: GString, from: Int64, to: Int64
) -> Int64 Returns the number of occurrences of the substring
what
betweenfrom
andto
positions, ignoring case. Ifto
is 0, the search continues until the end of the string.func dedent(
) -> GString Returns a copy of the string with indentation (leading tabs and spaces) removed. See also
indent(prefix:)
to add indentation.func endsWith(text: GString
) -> Bool Returns
true
if the string ends with the giventext
. See alsobeginsWith(text:)
.func erase(position: Int64, chars: Int64
) -> GString Returns a string with
chars
characters erased starting fromposition
. Ifchars
goes beyond the string’s length given the specifiedposition
, fewer characters will be erased from the returned string. Returns an empty string if eitherposition
orchars
is negative. Returns the original string unmodified ifchars
is0
.func find(what: GString, from: Int64
) -> Int64 Returns the index of the first occurrence of
what
in this string, or-1
if there are none. The search’s start can be specified withfrom
, continuing to the end of the string.func findn(what: GString, from: Int64
) -> Int64 Returns the index of the first case-insensitive occurrence of
what
in this string, or-1
if there are none. The starting search index can be specified withfrom
, continuing to the end of the string.func format(values: Variant, placeholder: GString
) -> GString Formats the string by replacing all occurrences of
placeholder
with the elements ofvalues
.func getBaseDir(
) -> GString If the string is a valid file path, returns the base directory name.
func getBasename(
) -> GString If the string is a valid file path, returns the full file path, without the extension.
func getExtension(
) -> GString If the string is a valid file name or path, returns the file extension without the leading period (
.
). Otherwise, returns an empty string.func getFile(
) -> GString If the string is a valid file path, returns the file name, including the extension.
func getSlice(delimiter: GString, slice: Int64
) -> GString Splits the string using a
delimiter
and returns the substring at indexslice
. Returns the original string ifdelimiter
does not occur in the string. Returns an empty string if theslice
does not exist.func getSliceCount(delimiter: GString
) -> Int64 Returns the total number of slices when the string is split with the given
delimiter
(seesplit(delimiter:allowEmpty:maxsplit:)
).func getSlicec(delimiter: Int64, slice: Int64
) -> GString Splits the string using a Unicode character with code
delimiter
and returns the substring at indexslice
. Returns an empty string if theslice
does not exist.func hash(
) -> Int64 Returns the 32-bit hash value representing the string’s contents.
func hash(into: inout Hasher
) func hexDecode(
) -> PackedByteArray Decodes a hexadecimal string as a
PackedByteArray
.func hexToInt(
) -> Int64 Converts the string representing a hexadecimal number into an integer. The string may be optionally prefixed with
"0x"
, and an additional-
prefix for negative numbers.func indent(prefix: GString
) -> GString Indents every line of the string with the given
prefix
. Empty lines are not indented. See alsodedent
to remove indentation.func insert(position: Int64, what: GString
) -> GString Inserts
what
at the givenposition
in the string.func isAbsolutePath(
) -> Bool Returns
true
if the string is a path to a file or directory, and its starting point is explicitly defined. This method is the opposite ofisRelativePath
.func isEmpty(
) -> Bool Returns
true
if the string’s length is0
(""
). See alsolength
.func isRelativePath(
) -> Bool Returns
true
if the string is a path, and its starting point is dependent on context. The path could begin from the current directory, or the currentNode
(if the string is derived from aNodePath
), and may sometimes be prefixed with"./"
. This method is the opposite ofisAbsolutePath
.func isSubsequenceOf(text: GString
) -> Bool Returns
true
if all characters of this string can be found intext
in their original order.func isSubsequenceOfn(text: GString
) -> Bool Returns
true
if all characters of this string can be found intext
in their original order, ignoring case.func isValidFilename(
) -> Bool Returns
true
if this string does not contain characters that are not allowed in file names (:
/
\
?
*
"
|
%
<
>
).func isValidFloat(
) -> Bool Returns
true
if this string represents a valid floating-point number. A valid float may contain only digits, one decimal point (.
), and the exponent letter (e
). It may also be prefixed with a positive (+
) or negative (-
) sign. Any valid integer is also a valid float (seeisValidInt
). See alsotoFloat
.func isValidHexNumber(withPrefix: Bool
) -> Bool Returns
true
if this string is a valid hexadecimal number. A valid hexadecimal number only contains digits or lettersA
toF
(either uppercase or lowercase), and may be prefixed with a positive (+
) or negative (-
) sign.func isValidHtmlColor(
) -> Bool Returns
true
if this string is a valid color in hexadecimal HTML notation. The string must be a hexadecimal value (seeisValidHexNumber(withPrefix:)
) of either 3, 4, 6 or 8 digits, and may be prefixed by a hash sign (#
). Other HTML notations for colors, such as names orhsl()
, are not considered valid. See alsohtml(rgba:)
.func isValidIdentifier(
) -> Bool Returns
true
if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores (_
), and the first character may not be a digit.func isValidInt(
) -> Bool Returns
true
if this string represents a valid integer. A valid integer only contains digits, and may be prefixed with a positive (+
) or negative (-
) sign. See alsotoInt
.func isValidIpAddress(
) -> Bool Returns
true
if this string represents a well-formatted IPv4 or IPv6 address. This method considers reserved IP addresses such as"0.0.0.0"
and"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
as valid.func join(parts: PackedStringArray
) -> GString Returns the concatenation of
parts
’ elements, with each element separated by the string calling this method. This method is the opposite ofsplit(delimiter:allowEmpty:maxsplit:)
.func jsonEscape(
) -> GString Returns a copy of the string with special characters escaped using the JSON standard. Because it closely matches the C standard, it is possible to use
cUnescape
to unescape the string, if necessary.func left(length: Int64
) -> GString Returns the first
length
characters from the beginning of the string. Iflength
is negative, strips the lastlength
characters from the string’s end.func length(
) -> Int64 Returns the number of characters in the string. Empty strings (
""
) always return0
. See alsoisEmpty
.func lpad(minLength: Int64, character: GString
) -> GString Formats the string to be at least
minLength
long by addingcharacter
s to the left of the string, if necessary. See alsorpad(minLength:character:)
.func lstrip(chars: GString
) -> GString Removes a set of characters defined in
chars
from the string’s beginning. See alsorstrip(chars:)
.func match(expr: GString
) -> Bool Does a simple expression match (also called “glob” or “globbing”), where
*
matches zero or more arbitrary characters and?
matches any single character except a period (.
). An empty string or empty expression always evaluates tofalse
.func matchn(expr: GString
) -> Bool Does a simple case-insensitive expression match, where
*
matches zero or more arbitrary characters and?
matches any single character except a period (.
). An empty string or empty expression always evaluates tofalse
.func md5Buffer(
) -> PackedByteArray Returns the MD5 hash of the string as a
PackedByteArray
.func md5Text(
) -> GString func naturalcasecmpTo(GString
) -> Int64 Performs a case-sensitive, natural order comparison to another string. Returns
-1
if less than,1
if greater than, or0
if equal. “Less than” or “greater than” are determined by the Unicode code points of each string, which roughly matches the alphabetical order.func naturalnocasecmpTo(GString
) -> Int64 Performs a case-insensitive, natural order comparison to another string. Returns
-1
if less than,1
if greater than, or0
if equal. “Less than” or “greater than” are determined by the Unicode code points of each string, which roughly matches the alphabetical order. Internally, lowercase characters are converted to uppercase for the comparison.func nocasecmpTo(GString
) -> Int64 Performs a case-insensitive comparison to another string. Returns
-1
if less than,1
if greater than, or0
if equal. “Less than” or “greater than” are determined by the Unicode code points of each string, which roughly matches the alphabetical order. Internally, lowercase characters are converted to uppercase for the comparison.func padDecimals(digits: Int64
) -> GString Formats the string representing a number to have an exact number of
digits
after the decimal point.func padZeros(digits: Int64
) -> GString Formats the string representing a number to have an exact number of
digits
before the decimal point.func pathJoin(file: GString
) -> GString Concatenates
file
at the end of the string as a subpath, adding/
if necessary.func replace(what: GString, forwhat: GString
) -> GString Replaces all occurrences of
what
inside the string with the givenforwhat
.func replacen(what: GString, forwhat: GString
) -> GString Replaces all case-insensitive occurrences of
what
inside the string with the givenforwhat
.func reverse(
) -> GString Returns the copy of this string in reverse order.
func rfind(what: GString, from: Int64
) -> Int64 Returns the index of the last occurrence of
what
in this string, or-1
if there are none. The search’s start can be specified withfrom
, continuing to the beginning of the string. This method is the reverse offind(what:from:)
.func rfindn(what: GString, from: Int64
) -> Int64 Returns the index of the last case-insensitive occurrence of
what
in this string, or-1
if there are none. The starting search index can be specified withfrom
, continuing to the beginning of the string. This method is the reverse offindn(what:from:)
.func right(length: Int64
) -> GString Returns the last
length
characters from the end of the string. Iflength
is negative, strips the firstlength
characters from the string’s beginning.func rpad(minLength: Int64, character: GString
) -> GString Formats the string to be at least
minLength
long, by addingcharacter
s to the right of the string, if necessary. See alsolpad(minLength:character:)
.func rsplit(delimiter: GString, allowEmpty: Bool, maxsplit: Int64
) -> PackedStringArray Splits the string using a
delimiter
and returns an array of the substrings, starting from the end of the string. The splits in the returned array appear in the same order as the original string. Ifdelimiter
is an empty string, each substring will be a single character.func rstrip(chars: GString
) -> GString Removes a set of characters defined in
chars
from the string’s end. See alsolstrip(chars:)
.func sha1Buffer(
) -> PackedByteArray Returns the SHA-1 hash of the string as a
PackedByteArray
.func sha1Text(
) -> GString func sha256Buffer(
) -> PackedByteArray Returns the SHA-256 hash of the string as a
PackedByteArray
.func sha256Text(
) -> GString func similarity(text: GString
) -> Double Returns the similarity index (Sorensen-Dice coefficient) of this string compared to another. A result of
1.0
means totally similar, while0.0
means totally dissimilar.func simplifyPath(
) -> GString If the string is a valid file path, converts the string into a canonical path. This is the shortest possible path, without
"./"
, and all the unnecessary".."
and"/"
.func split(delimiter: GString, allowEmpty: Bool, maxsplit: Int64
) -> PackedStringArray Splits the string using a
delimiter
and returns an array of the substrings. Ifdelimiter
is an empty string, each substring will be a single character. This method is the opposite ofjoin(parts:)
.func splitFloats(delimiter: GString, allowEmpty: Bool
) -> PackedFloat64Array Splits the string into floats by using a
delimiter
and returns aPackedFloat64Array
.func stripEdges(left: Bool, right: Bool
) -> GString Strips all non-printable characters from the beginning and the end of the string. These include spaces, tabulations (
\t
), and newlines (\n
\r
).func stripEscapes(
) -> GString Strips all escape characters from the string. These include all non-printable control characters of the first page of the ASCII table (values from 0 to 31), such as tabulation (
\t
) and newline (\n
,\r
) characters, but not spaces.func substr(from: Int64, len: Int64
) -> GString Returns part of the string from the position
from
with lengthlen
. Iflen
is-1
(as by default), returns the rest of the string starting from the given position.func toAsciiBuffer(
) -> PackedByteArray Converts the string to an ASCII/Latin-1 encoded
PackedByteArray
. This method is slightly faster thantoUtf8Buffer
, but replaces all unsupported characters with spaces. This is the inverse ofgetStringFromAscii
.func toCamelCase(
) -> GString Returns the string converted to
camelCase
.func toFloat(
) -> Double Converts the string representing a decimal number into a float. This method stops on the first non-number character, except the first decimal point (
.
) and the exponent letter (e
). See alsoisValidFloat
.func toInt(
) -> Int64 Converts the string representing an integer number into an integer. This method removes any non-number character and stops at the first decimal point (
.
). See alsoisValidInt
.func toLower(
) -> GString Returns the string converted to lowercase.
func toPascalCase(
) -> GString Returns the string converted to
PascalCase
.func toSnakeCase(
) -> GString Returns the string converted to
snake_case
.func toUpper(
) -> GString Returns the string converted to uppercase.
func toUtf16Buffer(
) -> PackedByteArray Converts the string to a UTF-16 encoded
PackedByteArray
. This is the inverse ofgetStringFromUtf16
.func toUtf32Buffer(
) -> PackedByteArray Converts the string to a UTF-32 encoded
PackedByteArray
. This is the inverse ofgetStringFromUtf32
.func toUtf8Buffer(
) -> PackedByteArray Converts the string to a UTF-8 encoded
PackedByteArray
. This method is slightly slower thantoAsciiBuffer
, but supports all UTF-8 characters. For most cases, prefer using this method. This is the inverse ofgetStringFromUtf8
.func toWcharBuffer(
) -> PackedByteArray Converts the string to a wide character (
wchar_t
, UTF-16 on Windows, UTF-32 on other platforms) encodedPackedByteArray
. This is the inverse ofgetStringFromWchar
.func trimPrefix(GString
) -> GString Removes the given
prefix
from the start of the string, or returns the string unchanged.func trimSuffix(GString
) -> GString Removes the given
suffix
from the end of the string, or returns the string unchanged.func unicodeAt(Int64
) -> Int64 Returns the character code at position
at
.func uriDecode(
) -> GString Decodes the string from its URL-encoded format. This method is meant to properly decode the parameters in a URL when receiving an HTTP request. See also
uriEncode
.func uriEncode(
) -> GString Encodes the string to URL-friendly format. This method is meant to properly encode the parameters in a URL when sending an HTTP request. See also
uriDecode
.func validateFilename(
) -> GString Returns a copy of the string with all characters that are not allowed in
isValidFilename
replaced with underscores.func validateNodeName(
) -> GString Returns a copy of the string with all characters that are not allowed in
name
(.
:
@
/
"
%
) replaced with underscores.func xmlEscape(escapeQuotes: Bool
) -> GString Returns a copy of the string with special characters escaped using the XML standard. If
escapeQuotes
istrue
, the single quote ('
) and double quote ("
) characters are also escaped.func xmlUnescape(
) -> GString Returns a copy of the string with escaped characters replaced by their meanings according to the XML standard.
Type features
init?(Variant
) init(extendedGraphemeClusterLiteral: Self.StringLiteralType
) init(stringInterpolation: DefaultStringInterpolation
) Creates a new instance from an interpolated string literal.
init(unicodeScalarLiteral: Self.ExtendedGraphemeClusterLiteralType
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.