Class: Toybox::Lang::String

Inherits:
Object
  • Object
show all

Overview

String objects represent a sequence of characters, and provide methods for string operations.

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Object

method, weak

Instance Method Details

equals(object) ⇒ Toybox::Lang::Boolean

Test if an Object instance is equal to another instance of an Object.

Parameters:

Returns:

Since:

  • 1.0.0


6782
6783
# File 'Monkeybrains.rb', line 6782

def equals(object)
end

find(string) ⇒ Toybox::Lang::Number

Determine if the specified String exists in a String.

Examples:

var myString = "Go bananas with Monkey C!";
var index = myString.find("bananas"); // index is 3

Parameters:

Returns:

Since:

  • 1.0.0


6793
6794
# File 'Monkeybrains.rb', line 6793

def find(string)
end

hashCodeToybox::Lang::Number

Get a hash code value for a String.

Returns:

Since:

  • 1.0.0


6768
6769
# File 'Monkeybrains.rb', line 6768

def hashCode()
end

lengthToybox::Lang::Number

Get the number of characters in a String.

Returns:

Since:

  • 1.0.0


6774
6775
# File 'Monkeybrains.rb', line 6774

def length()
end

substring(startIndex, endIndex) ⇒ Toybox::Lang::String

Create a new String that contains the contents of the current String from a start position to an end position.

Examples:

var myString = "Go bananas with Monkey C!";
var mySubString = myString.subString(3, 10); // mySubString is "bananas"

Parameters:

Returns:

Since:

  • 1.0.0


6808
6809
# File 'Monkeybrains.rb', line 6808

def substring(startIndex, endIndex)
end

toCharArrayToybox::Lang::Array

Convert a String to an Array of Char objects.

Returns:

  • (Toybox::Lang::Array)

    A Char Array representation of the String, where each character in the String is an element in the Array

Since:

  • 1.3.0


6833
6834
# File 'Monkeybrains.rb', line 6833

def toCharArray()
end

toDoubleToybox::Lang::Double

Convert a String to a Double.

If a String is in the numeric form of “123” or “123.45”, convert it to a Double. Additional characters after the detected floating point value will be ignored. Strings that cannot be interpreted as a Double, or whose value exceeds that which can be represented in a Double, will result in a null value.

Examples:

var myString;
var myNum;

myString = "123";
myNum = myString.toDouble(); // myNum is 123.000000

myString = "3.14"
myNum = myString.toDouble(); // myNum is 3.140000

myString = "192.168.0.1"
myNum = myString.toDouble(); // myNum is 192.167999

myString = "Hello There!"
myNum = myString.toDouble(); // null

Returns:

Since:

  • 3.1.0


6735
6736
# File 'Monkeybrains.rb', line 6735

def toDouble()
end

toFloatToybox::Lang::Float

Convert a String to a Float.

If a String is in the numeric form of “123” or “123.45”, convert it to a Float. Additional characters after the detected floating point value will be ignored. Strings that cannot be interpreted as a Float, or whose value exceeds that which can be represented in a Float, will result in a null value.

Examples:

var myString;
var myNum;

myString = "123";
myNum = myString.toFloat(); // myNum is 123.000000

myString = "3.14"
myNum = myString.toFloat(); // myNum is 3.140000

myString = "192.168.0.1"
myNum = myString.toFloat(); // myNum is 192.167999

myString = "Hello There!"
myNum = myString.toFloat(); // null

Returns:

Since:

  • 1.0.0


6762
6763
# File 'Monkeybrains.rb', line 6762

def toFloat()
end

toLongToybox::Lang::Long

Convert a String to a Long.

If a String is in the numeric form of “123”, it can be converted to a Long. Additional characters after the detected number value will be ignored. Strings that cannot be interpreted as a Long, or whose value exceeds that which can be represented in a Long, will result in a null value.

Examples:

var myString;
var myNum;

myString = "123";
myNum = myString.toLong(); // myNum is 123

myString = "3.14"
myNum = myString.toLong(); // myNum is 3

myString = "1200 E. 151st. Street"
myNum = myString.toLong(); // myNum is 1200

myString = "Hello There!"
myNum = myString.toLong(); // null

Returns:

Since:

  • 3.1.0


6631
6632
# File 'Monkeybrains.rb', line 6631

def toLong()
end

toLongWithBase(base) ⇒ Toybox::Lang::Long

Convert a String to a Long using a specified base.

Examples:

var myString;
var myNum;

myString = "10";
myNum = myString.toLongWithBase(2);    // myNum is 2

myString = "FF";
myNum = myString.toLongWithBase(16);   // myNum is 255
myNum = myString.toLongWithBase(0x10); // myNum is 255

Parameters:

  • base (Toybox::Lang::Object)

    The base of the input string. If the value of base is zero, the string content is expected to have syntax similar to that of integer constants, which includes:

    • An optional sign character ('+' or '-')

    • An optional prefix for octal or hexadecimal ('0' or '0x')

    • A sequence of digits in the prefixed base, or decimal if none was specified.

    If the base value is between 2 and 36, the format expected for the number is valid digits and/or letters that represent integers of the specified radix (from '0' to 'z' or 'Z' for base 36).

Returns:

Since:

  • 1.4.1


6656
6657
# File 'Monkeybrains.rb', line 6656

def toLongWithBase(base)
end

toLowerToybox::Lang::String

Convert a String to lowercase.

Returns:

Since:

  • 1.0.0


6814
6815
# File 'Monkeybrains.rb', line 6814

def toLower()
end

toNumberToybox::Lang::Number

Convert a String to a Number.

If a String is in the numeric form of “123”, it can be converted to a Number. Additional characters after the detected number value will be ignored. Strings that cannot be interpreted as a Number, or whose value exceeds that which can be represented in a Number, will result in a null value.

Examples:

var myString;
var myNum;

myString = "123";
myNum = myString.toNumber(); // myNum is 123

myString = "3.14"
myNum = myString.toNumber(); // myNum is 3

myString = "1200 E. 151st. Street"
myNum = myString.toNumber(); // myNum is 1200

myString = "Hello There!"
myNum = myString.toNumber(); // null

Returns:

Since:

  • 1.0.0


6683
6684
# File 'Monkeybrains.rb', line 6683

def toNumber()
end

toNumberWithBase(base) ⇒ Toybox::Lang::Number

Convert a String to a Number using a specified base.

Examples:

var myString;
var myNum;

myString = "10";
myNum = myString.toNumberWithBase(2);    // myNum is 2

myString = "FF";
myNum = myString.toNumberWithBase(16);   // myNum is 255
myNum = myString.toNumberWithBase(0x10); // myNum is 255

Parameters:

  • base (Toybox::Lang::Object)

    The base of the input string. If the value of base is zero, the string content expected to have syntax similar to that of integer constants, which includes:

    • An optional sign character ('+' or '-')

    • An optional prefix for octal or hexadecimal ('0' or '0x')

    • A sequence of digits in the prefixed base, or decimal if none was specified.

    If the base value is between 2 and 36, the format expected for the number is valid digits and/or letters that represent integers of the specified radix (from '0' to 'z' or 'Z' for base 36).

Returns:

Since:

  • 1.4.1


6708
6709
# File 'Monkeybrains.rb', line 6708

def toNumberWithBase(base)
end

toStringToybox::Lang::String

Convert a String to a String.

Returns:

Since:

  • 1.0.0


6826
6827
# File 'Monkeybrains.rb', line 6826

def toString()
end

toUpperToybox::Lang::String

Convert a String to uppercase.

Returns:

Since:

  • 1.0.0


6820
6821
# File 'Monkeybrains.rb', line 6820

def toUpper()
end

toUtf8ArrayToybox::Lang::Array

Convert a String to an Array of Number objects.

Each Number represents one byte of the UTF-8 representation of the String.

Returns:

  • (Toybox::Lang::Array)

    An Array representation of the String, where each byte in the string is an element in the Array

Since:

  • 1.3.0


6842
6843
# File 'Monkeybrains.rb', line 6842

def toUtf8Array()
end