Instance Methodmigueldeicaza.swiftgodot 0.45.0SwiftGodot
toFloat
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 also isValidFloat
.
final func toFloat() -> Double
Other members in extension
Typealiases
Type members
init(
) Constructs an empty
StringName
.init(String
) init(String.SubSequence
) Creates a StringName from a Swift String.Substring
init(alreadyOwnedContent: ContentType
) init(content: ContentType
) init(from: StringName
) Constructs a
StringName
as a copy of the givenStringName
.init(from: String
) Creates a new
StringName
from the givenString
. In GDScript,StringName("example")
is equivalent to&"example"
.init(fromPtr: UnsafeRawPointer?
) init(stringLiteral: String
) static var godotType: Variant.GType
static let zero: ContentType
static func != (lhs: StringName, rhs: StringName
) -> Bool Returns
true
if thisStringName
is not equivalent to the givenString
.static func != (lhs: StringName, rhs: String
) -> Bool Returns
true
if thisStringName
is not equivalent to the givenString
.static func % (lhs: StringName, rhs: PackedStringArray
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Projection
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Quaternion
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: GDictionary
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Transform2D
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Transform3D
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedByteArray
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedColorArray
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedInt32Array
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedInt64Array
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedFloat32Array
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedFloat64Array
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedVector2Array
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: PackedVector3Array
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: AABB
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Basis
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Color
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Plane
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Rect2
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: GArray
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Object
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Rect2i
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Signal
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Vector2
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Vector3
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Vector4
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Callable
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: NodePath
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Vector2i
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Vector3i
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Vector4i
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: StringName
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: String
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Bool
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Double
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func % (lhs: StringName, rhs: Int64
) -> String Formats the
StringName
, replacing the placeholders with one or more parameters, returning aString
. To pass multiple parameters,right
needs to be anGArray
.static func + (lhs: StringName, rhs: StringName
) -> String Appends
right
at the end of thisStringName
, returning aString
. This is also known as a string concatenation.static func + (lhs: StringName, rhs: String
) -> String Appends
right
at the end of thisStringName
, returning aString
. This is also known as a string concatenation.static func < (lhs: StringName, rhs: StringName
) -> Bool Returns
true
if the leftStringName
’s pointer comes beforeright
. Note that this will not match their Unicode order.static func <= (lhs: StringName, rhs: StringName
) -> Bool Returns
true
if the leftStringName
’s pointer comes beforeright
or if they are the same. Note that this will not match their Unicode order.static func == (lhs: StringName, rhs: StringName
) -> Bool Compares two StringNames for equality.
static func == (lhs: StringName, rhs: String
) -> Bool Returns
true
if thisStringName
is equivalent to the givenString
.static func > (lhs: StringName, rhs: StringName
) -> Bool Returns
true
if the leftStringName
’s pointer comes afterright
. Note that this will not match their Unicode order.static func >= (lhs: StringName, rhs: StringName
) -> Bool Returns
true
if the leftStringName
’s pointer comes afterright
or if they are the same. Note that this will not match their Unicode order.
Instance members
var content: ContentType
var description: String
Returns a Swift string from the StringName
func beginsWith(text: String
) -> 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(
) -> String Returns a copy of the string with special characters escaped using the C language standard.
func cUnescape(
) -> String 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(
) -> String 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(String
) -> 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: String
) -> Bool Returns
true
if the string containswhat
. In GDScript, this corresponds to thein
operator.func count(what: String, 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: String, 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(
) -> String Returns a copy of the string with indentation (leading tabs and spaces) removed. See also
indent(prefix:)
to add indentation.func endsWith(text: String
) -> Bool Returns
true
if the string ends with the giventext
. See alsobeginsWith(text:)
.func erase(position: Int64, chars: Int64
) -> String 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: String, 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: String, 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: String
) -> String Formats the string by replacing all occurrences of
placeholder
with the elements ofvalues
.func getBaseDir(
) -> String If the string is a valid file path, returns the base directory name.
func getBasename(
) -> String If the string is a valid file path, returns the full file path, without the extension.
func getExtension(
) -> String 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(
) -> String If the string is a valid file path, returns the file name, including the extension.
func getSlice(delimiter: String, slice: Int64
) -> String Splits the string using a
delimiter
and returns the substring at indexslice
. Returns an empty string if theslice
does not exist.func getSliceCount(delimiter: String
) -> 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
) -> String 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: String
) -> String 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: String
) -> String 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: String
) -> Bool Returns
true
if all characters of this string can be found intext
in their original order.func isSubsequenceOfn(text: String
) -> 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
) -> String 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(
) -> String 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
) -> String 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: String
) -> String 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: String
) -> String Removes a set of characters defined in
chars
from the string’s beginning. See alsorstrip(chars:)
.func match(expr: String
) -> 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: String
) -> 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(
) -> String Returns the MD5 hash of the string as another
String
.func naturalcasecmpTo(String
) -> 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(String
) -> 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(String
) -> 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
) -> String Formats the string representing a number to have an exact number of
digits
after the decimal point.func padZeros(digits: Int64
) -> String Formats the string representing a number to have an exact number of
digits
before the decimal point.func pathJoin(file: String
) -> String Concatenates
file
at the end of the string as a subpath, adding/
if necessary.func replace(what: String, forwhat: String
) -> String Replaces all occurrences of
what
inside the string with the givenforwhat
.func replacen(what: String, forwhat: String
) -> String Replaces all case-insensitive occurrences of
what
inside the string with the givenforwhat
.func reverse(
) -> String Returns the copy of this string in reverse order.
func rfind(what: String, 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: String, 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
) -> String 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: String
) -> String 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: String, 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: String
) -> String 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(
) -> String Returns the SHA-1 hash of the string as another
String
.func sha256Buffer(
) -> PackedByteArray Returns the SHA-256 hash of the string as a
PackedByteArray
.func sha256Text(
) -> String Returns the SHA-256 hash of the string as another
String
.func similarity(text: String
) -> 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(
) -> String 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: String, 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: String, allowEmpty: Bool
) -> PackedFloat64Array Splits the string into floats by using a
delimiter
and returns aPackedFloat64Array
.func stripEdges(left: Bool, right: Bool
) -> String 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(
) -> String 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
) -> String 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.func toCamelCase(
) -> String Returns the string converted to
camelCase
.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(
) -> String Returns the string converted to lowercase.
func toPascalCase(
) -> String Returns the string converted to
PascalCase
.func toSnakeCase(
) -> String Returns the string converted to
snake_case
.func toUpper(
) -> String Returns the string converted to uppercase.
func toUtf16Buffer(
) -> PackedByteArray Converts the string to a UTF-16 encoded
PackedByteArray
.func toUtf32Buffer(
) -> PackedByteArray Converts the string to a UTF-32 encoded
PackedByteArray
.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.func toWcharBuffer(
) -> PackedByteArray Converts the string to a wide character (
wchar_t
, UTF-16 on Windows, UTF-32 on other platforms) encodedPackedByteArray
.func trimPrefix(String
) -> String Removes the given
prefix
from the start of the string, or returns the string unchanged.func trimSuffix(String
) -> String 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(
) -> String 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.
func uriEncode(
) -> String Encodes the string to URL-friendly format. This method is meant to properly encode the parameters in a URL when sending an HTTP request.
func validateFilename(
) -> String Returns a copy of the string with all characters that are not allowed in
isValidFilename
replaced with underscores.func validateNodeName(
) -> String Returns a copy of the string with all characters that are not allowed in
name
(.
:
@
/
"
%
) replaced with underscores.func xmlEscape(escapeQuotes: Bool
) -> String 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(
) -> String Returns a copy of the string with escaped characters replaced by their meanings according to the XML standard.