---
title: Data
description: 
published: 1
date: 2021-12-14T18:36:35.412Z
tags: 
editor: markdown
dateCreated: 2020-12-17T18:55:14.582Z
---

# Data

| ![][menu]  | [![][b1]][d1]&nbsp;&nbsp;&nbsp; [![][b2]][d2]&nbsp;&nbsp;&nbsp; [![][b3]][d3]&nbsp;&nbsp;&nbsp;[![][b4]][d4]&nbsp;&nbsp;&nbsp; <br> [![][b5]][d5]&nbsp;&nbsp;&nbsp; [![][b6]][d6]&nbsp;&nbsp;&nbsp; [![][b7]][d7]<br> [![][b8]][d8]&nbsp;&nbsp;&nbsp;[![][b9]][d9]&nbsp;&nbsp;&nbsp;[![][b10]][d10]<br> [![][b11]][d11]&nbsp;&nbsp;&nbsp; [![][b12]][d12] &nbsp;&nbsp;&nbsp; [![][b13]][d13]<br> [![][b14]][d14]&nbsp;&nbsp;&nbsp; [![][b15]][d15]&nbsp;&nbsp;&nbsp; [![][b16]][d16]  <br> [![][b17]][d17]|
|---|:---|

<!--- (COMMENT - INPUT Category Images (Used above)
-->
[spacer]: /reference_manual/data/spacer.png
[menu]: /reference_manual/menus/menu_data_70p.png
[b1]: /reference_manual/data/item_50p.png
[b2]: /reference_manual/data/length_50p.png
[b3]: /reference_manual/data/join_50p.png
[b4]: /reference_manual/data/list_50p.png
[b5]: /reference_manual/data/addlist_50p.png
[b6]: /reference_manual/data/replace_50p.png
[b7]: /reference_manual/data/delete_50p.png
[b8]: /reference_manual/data/find_50p.png
[b9]: /reference_manual/data/copy_50p.png
[b10]: /reference_manual/data/split_50p.png
[b11]: /reference_manual/data/joinitems_50p.png
[b12]: /reference_manual/data/unicode_50p.png
[b13]: /reference_manual/data/stringunicode_50p.png
[b14]: /reference_manual/data/newlist_50p.png
[b15]: /reference_manual/data/newbyte_50p.png
[b16]: /reference_manual/data/asbytearray_50p.png
[b17]: /reference_manual/data/freemem_50p.png

<!--- (COMMENT - INPUT Category Detail Bookmarks (Used above)
-->
[d1]: /reference_manual/data#item
[d2]: /reference_manual/data#length-of
[d3]: /reference_manual/data#join
[d4]: /reference_manual/data#list
[d5]: /reference_manual/data#add-to-list
[d6]: /reference_manual/data#replace-item
[d7]: /reference_manual/data#delete-item
[d8]: /reference_manual/data#find
[d9]: /reference_manual/data#copy
[d10]: /reference_manual/data#split
[d11]: /reference_manual/data#join-items-of-list
[d12]: /reference_manual/data#unicode
[d13]: /reference_manual/data#string-from-unicode
[d14]: /reference_manual/data#new-list
[d15]: /reference_manual/data#new-byte-array
[d16]: /reference_manual/data#as-byte-array
[d17]: /reference_manual/data#free-memory



## <br>item
## Tab {.tabset}
### Description
![](/reference_manual/data/item.png)
Returns n_th character of a string or n_th item of a list, depending on the type of the input value.

### Example
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.

![](/reference_manual/data/code_item.png)

[Download Example](/reference_manual/examples/code_item.ubp)


## <br>length of
## Tab {.tabset}
### Description
![](/reference_manual/data/length.png)
Returns the length (# of characters) of a string or length (# of items) of a list, depending on the type of the input value.

### Example
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.

![](/reference_manual/data/code_length.png)

[Download Example](/reference_manual/examples/code_length.ubp)


## <br>join
## Tab {.tabset}
### Description
![](/reference_manual/data/join.png)
Combines strings or lists and returns the result. Both inputs must be of the same type.

### Example
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.

![](/reference_manual/data/code_join.png)

[Download Example](/reference_manual/examples/code_join.ubp)


## <br> list
## Tab {.tabset}
### Description
![](/reference_manual/data/list.png)
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.

### Example
The program demonstrates the creation of an empty list and one with four items.

![](/reference_manual/data/code_list.png)

[Download Example](/reference_manual/examples/code_list.ubp)


## <br> add to list
## Tab {.tabset}
### Description
![](/reference_manual/data/addlist.png)

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.

### Example
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.

![](/reference_manual/data/code_addlist.png)

[Download Example](/reference_manual/examples/code_addlist.ubp)


## <br> replace item
## Tab {.tabset}
### Description
![](/reference_manual/data/replace.png)
Replaces the n_th item of a list with the value specified in the input.
The item numbers start at 1.

### Example
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.

![](/reference_manual/data/code_replace.png)

[Download Example](/reference_manual/examples/code_replace.ubp)


## <br> delete item
## Tab {.tabset}
### Description
![](/reference_manual/data/delete.png)
Deletes the n_th item of a list. The resulting list is reduced in size.

### Example
The program deletes the first item of the list (cat), and then displays the remaining items of the list.

![](/reference_manual/data/code_delete.png)

[Download Example](/reference_manual/examples/code_delete.ubp)


## <br> find
## Tab {.tabset}
### Description
![](/reference_manual/data/find.png)
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.

### Example
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.


![](/reference_manual/data/code_find.png)

[Download Example](/reference_manual/examples/code_find.ubp)


## <br> copy
## Tab {.tabset}
### Description
![](/reference_manual/data/copy.png)
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.

### Example
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.

![](/reference_manual/data/code_copy.png)

[Download Example](/reference_manual/examples/code_copy.ubp)


## <br> split
## Tab {.tabset}
### Description
![](/reference_manual/data/split.png)
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.

### Example

![](/reference_manual/examples/code_split_ex1.png)
The comma delimited string is split by the comma delimiter into a three item list.

![](/reference_manual/examples/code_split_ex2.png)
A string that includes a newline character after the ABC is split by the newline delimiter into a two item list.

![](/reference_manual/examples/code_split_ex3.png)
Here we split the **MicroBlocks latest downloads URL** into its components by the / delimiter.

![](/reference_manual/examples/code_split_ex4.png)
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.

## <br> Advanced
## <br> join items of list
## Tab {.tabset}
### Description
![](/reference_manual/data/joinitems.png)
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.

### Example
The program initializes a three item list and then displays the items using a separator.

![](/reference_manual/data/code_joinitems.png)

[Download Example](/reference_manual/examples/code_joinitems.ubp)


## <br> unicode
## Tab {.tabset}
### Description
![](/reference_manual/data/unicode.png)
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.

### Example
The program displays the unicode value for the third character of the string "HELLO"; L = 76.

![](/reference_manual/data/code_unicode.png)

[Download Example](/reference_manual/examples/code_unicode.ubp)


## <br> string from unicode
## Tab {.tabset}
### Description
![](/reference_manual/data/stringunicode.png)
Returns the Unicode character symbol for the decimal number entered.

### Example
The program generates the uppercase letters of the alphabet from their unicodes and displays them. Letter A = 65, Z = 90.

![](/reference_manual/data/code_stringunicode.png)

[Download Example](/reference_manual/examples/code_stringunicode.ubp)


## <br> new list
## Tab {.tabset}
### Description
![](/reference_manual/data/newlist.png)
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 _**.

### Example
A new list of twelve items is created. All the items are initialized to value 999. Then the list is displayed.

![](/reference_manual/data/code_newlist.png)

[Download Example](/reference_manual/examples/code_newlist.ubp)


## <br> new byte array
## Tab {.tabset}
### Description
![](/reference_manual/data/newbyte.png)
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.

### Example
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.

![](/reference_manual/data/code_newbyte.png)

[Download Example](/reference_manual/examples/code_newbyte.ubp)


## <br> as byte array
## Tab {.tabset}
### Description
![](/reference_manual/data/asbytearray.png)
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.

### Example
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.

![](/reference_manual/data/code_asbytearray.png)

> 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**.
{.is-info}


[Download Example](/reference_manual/examples/code_asbytearray.ubp)


## <br>free memory
## Tab {.tabset}
### Description
![](/reference_manual/data/freemem.png)

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.
