Returns n_th character of a string or n_th item of a list, depending on the type of the input value.
The program initializes two variables: a string and a list.
It then displays the ninth character of the string and second item of the list.
Returns the length (# of characters) of a string or length (# of items) of a list, depending on the type of the input value.
The program displays the lengths of the string and the list.
To format the two groups of display with a new line, a STRING FROM UNICODE 10 block is used.
Combines strings or lists and returns the result. Both inputs must be of the same type.
The program displays two joined strings and two joined lists.
Notice that the display of the joined lists only shows the total item count of the joined list.
To actually get a listing of the items, the JOIN ITEMS OF LIST block needs to be used.
See example further below.
This block creates a list. The item count can vary from none (empty list) to the amount memory conditions allow. Additional items can be added by expanding the input areas with the black triangle.
The program demonstrates the creation of an empty list and one with four items.
Adds an item to the end of a list. Since lists can contain any data type, the added item can be of any data type.
The program adds three items to an empty list called animals.
The list and its items are displayed. To display each item of the list the JOIN ITEMS OF LIST block is used, with a comma as delimiter.
Replaces the n_th item of a list with the value specified in the input.
The item numbers start at 1.
The program initializes an empty list and adds three items to it.
Then item number 2 (dog) is replaced by fish.
List items are displayed.
Deletes the n_th item of a list. The resulting list is reduced in size.
The program deletes the first item of the list (cat), and then displays the remaining items of the list.
Locates a string within a string or an item in a list. A string search will return matching character position. A list search will return matching item number. No match returns -1.
The expanded mode of the find (starting at) allows he search to start at a selected character position for strings. The same mode applied to the lists allows the search to start at the selected item number.
The local variables string and animals are initialized as of type string and list respectively.
First set of finds operate on the string, looking for the occurrences of "is".
First match is found at character number three. The second search is started at character number five, and locates the search target at character number six. The third string search starts at the end of the string, and thus does not locate any matches, returning -1.
The list search looking for "dog" locates it at item number two of the list. The second list search looking for "bird" is directed to start at item number three, and locates it right there. There is no "fish" in the list, so the search returns -1.
Copies a string from/to specified characters positions, or a list from/to specified item numbers. In oder to specify the to parameter, the expanded mode by clicking the black triangle, needs to be accessed.
The example initializes a 17 character string and a three item list.
The first string copy operation copies the string from character five to the end: is a string,
The second string copy extracts characters 11 through 13: str.
The third string copy does not locate anything, as the start location is beyond the end of the string.
The list copy operations extract third item bird, first item cat, and zero items respectively.
Notice that all list copies return results in list format.
Returns a list by splitting the specified string by the optional delimiter. If no delimiter is specified, then the string is split by each character.
The comma delimited string is split by the comma delimiter into a three item list.
A string that includes a newline character after the ABC is split by the newline delimiter into a two item list.
Here we split the MicroBlocks latest downloads URL into its components by the / delimiter.
If you ever copy in a numeric data from another app (eg: calculator) or web page, it might arrive in edited format. We can convert it into integer format by a set of simple operations.
This join block takes items of a list and combines them into a string. If the expanded mode is used and a separator is specified, then the list items are delimited by the separator. Any string can be used as a separator.
Notice that there is no separator after the last list item.
The program initializes a three item list and then displays the items using a separator.
Returns the Unicode value of the n_th character of the string input. The character number entered must be between one and the length of the string. This block is the opposite operation of the following STRING FROM UNICODE block.
The program displays the unicode value for the third character of the string "HELLO"; L = 76.
Returns the Unicode character symbol for the decimal number entered.
The program generates the uppercase letters of the alphabet from their unicodes and displays them. Letter A = 65, Z = 90.
Creates a new list of n items specified, pending memory availability.
The items of the list created can be initialized to any value using the block option with all _.
A new list of twelve items is created. All the items are initialized to value 999. Then the list is displayed.
Creates an array of n items specified pending memory availability. Each item is of byte size and can be assigned values in the range of 0-255.
A new byte array of nine items is created. All the items are initialized to HEX value FF (0xFF). Then the first and last items of the array is displayed.
Converts a byte, a list, or a string specified into a byte array. Each item is the unicode value of the string letters in the range of 0-255.
This block is specially helpful when used with the Serial IO blocks, where there might be a need to provide a byte array as input.
Serial write block is used to send out the string HELLO as a byte array. Pins 0 and 1 loopback setting allows reading and display of the sent message on micro:bit display.
Please note that in the above example, the assignment of as byte array HELLO to the variable BUFFER is not necessary. It is only done so to illustrate the use of the "as byte array" block. We could have easily used the simpler version: serial write HELLO.
Returns a string indicating the number of 32-bit words of dynamic memory available for allocating new objects (strings, lists, or byte arrays). Clicking the stop button releases all memory. Right after clicking the stop button, this block reports the total dynamic memory available on a given device. Devices have differing amounts of dynamic memory, based on the amount of RAM proided by the hardware. For example, the micro:bit v2 has much more RAM than the original micro:bit.