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



5474
5475
# File 'Monkeybrains.rb', line 5474

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



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

def find(string)
end

hashCodeToybox::Lang::Number

Get a hash code value for a String.

Returns:

Since:

  • 1.0.0



5460
5461
# File 'Monkeybrains.rb', line 5460

def hashCode()
end

lengthToybox::Lang::Number

Get the number of characters in a String.

Returns:

Since:

  • 1.0.0



5466
5467
# File 'Monkeybrains.rb', line 5466

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



5500
5501
# File 'Monkeybrains.rb', line 5500

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



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

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



5454
5455
# File 'Monkeybrains.rb', line 5454

def toFloat()
end

toLowerToybox::Lang::String

Convert a String to lowercase.

Returns:

Since:

  • 1.0.0



5506
5507
# File 'Monkeybrains.rb', line 5506

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



5403
5404
# File 'Monkeybrains.rb', line 5403

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



5428
5429
# File 'Monkeybrains.rb', line 5428

def toNumberWithBase(base)
end

toStringToybox::Lang::String

Convert a String to a String.

Returns:

Since:

  • 1.0.0



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

def toString()
end

toUpperToybox::Lang::String

Convert a String to uppercase.

Returns:

Since:

  • 1.0.0



5512
5513
# File 'Monkeybrains.rb', line 5512

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



5534
5535
# File 'Monkeybrains.rb', line 5534

def toUtf8Array()
end