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


5492
5493
# File 'Monkeybrains.rb', line 5492

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


5503
5504
# File 'Monkeybrains.rb', line 5503

def find(string)
end

hashCodeToybox::Lang::Number

Get a hash code value for a String.

Returns:

Since:

  • 1.0.0


5478
5479
# File 'Monkeybrains.rb', line 5478

def hashCode()
end

lengthToybox::Lang::Number

Get the number of characters in a String.

Returns:

Since:

  • 1.0.0


5484
5485
# File 'Monkeybrains.rb', line 5484

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


5518
5519
# File 'Monkeybrains.rb', line 5518

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


5543
5544
# File 'Monkeybrains.rb', line 5543

def toCharArray()
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 passed to toFloat() that do not start with a number value will cause an Invalid Value error.

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(); // Invalid Value error

Returns:

Since:

  • 1.0.0


5472
5473
# File 'Monkeybrains.rb', line 5472

def toFloat()
end

toLowerToybox::Lang::String

Convert a String to lowercase.

Returns:

Since:

  • 1.0.0


5524
5525
# File 'Monkeybrains.rb', line 5524

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 passed to toNumber() that do not start with a number value will cause an Invalid Value error.

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(); // Invalid Value error

Returns:

Since:

  • 1.0.0


5421
5422
# File 'Monkeybrains.rb', line 5421

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


5446
5447
# File 'Monkeybrains.rb', line 5446

def toNumberWithBase(base)
end

toStringToybox::Lang::String

Convert a String to a String.

Returns:

Since:

  • 1.0.0


5536
5537
# File 'Monkeybrains.rb', line 5536

def toString()
end

toUpperToybox::Lang::String

Convert a String to uppercase.

Returns:

Since:

  • 1.0.0


5530
5531
# File 'Monkeybrains.rb', line 5530

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


5552
5553
# File 'Monkeybrains.rb', line 5552

def toUtf8Array()
end