Strings#
Introduction#
The Strings blocks in VEXcode AIR handle string manipulations and the processing of text.
Below is a list of available blocks:
join — Combines two strings into one.
letter — Extracts a character from a string by position.
length — Returns the number of characters in a string.
contains — Checks if a string includes a specific word or character.
convert — Converts a number into text, a whole number, or a decimal.
join#
The join block combines two or more strings into a single string. It returns a string that contains the combined text of the given inputs.
(join [apple] [banana])
parameter |
description |
---|---|
string 1 |
The first string to combine. |
string 2 |
The second string to combine. |
Example
when started :: hat events
[Display "VEXcode" on the Console.]
print (join [VEX] [code]) on Console ▶
letter#
The letter block extracts a specific character from a string based on its position. It returns a single-character string, representing the letter at the given position.
(letter [1] of [apple])
parameter |
description |
---|---|
position |
The position of the character in the string (starting at 1). |
string |
The string to extract a letter from. |
Example
when started :: hat events
[Display the first letter of "drone".]
print (letter (1) of [drone]) on Console ▶
length#
The length block reports the number of characters in a string, including spaces. It returns a whole number, representing the total number of characters.
(length of [apple])
parameter |
description |
---|---|
string |
The string to measure the length of. |
Example
when started :: hat events
[Count the number of characters in "VEX Robotics".]
print (length of [VEX Robotics]) on Console ▶
contains#
The contains block checks if a string includes a specific word or character. It returns either True or False.
True — The string includes that specific word or character.
False — The string does not include that specific word or character.
<[apple] contains [a] ?>
parameter |
description |
---|---|
string |
The main string to search within. |
search term |
The word or character to check for inside the string. |
Example
when started :: hat events
[Check if "robotics" contains "bot".]
if <[robotics] contains [bot] ?> then
print [The word contains "bot".] on Console ▶
else
print [Not found.] on Console ▶
end
convert#
The convert block changes a number into a different format: a string or decimal number. It returns the value in the selected format:
text — Converts the number to a string. Numbers must be in string format to work with String Operator blocks.
number — Converts the number to a decimal (floating-point) value.
(convert [0] to [text v])
parameter |
description |
---|---|
value |
The number to convert. |
type |
The type to convert the number into:
|
Example
when started :: hat events
[Add any number to 5.]
ask [Give me a number.] and wait
print ((convert (answer) to [number v]) [math_plus v] [5]) on console ▶