Beginner's guide: Text blocks

This is purely a beginner’s tutorial.

I will show the things you can do with the different text blocks.

This is a textstring block

image

Default it is empty but you can fill it with a lot of different things. Some samples you can find below.

image

When a Text string block reaches a certain number of characters the text is only partially displayed. You see three dots … at the end of the visible part of the text string. The rest of the text string is still there, just not visible.

image

You can find the Text string block in the Text category of the Blockeditor. You can drag and drop it in the Blockeditor. When you click on the pink part of the Text string block you can type text or you can paste text that you got somewhere else.

The Text string block is one of most used blocks in a lot of projects. Here are some samples.

You don’t have to understand what every block means. It is just to show you how Text string blocks can be used.

When a Text string block is filled with a number it acts the same as a number block with the same value. Number blocks will be discussed in a different Beginners guide.

image

A space in a Textstring block also takes up space. :grin:

Below you can see different Text string blocks with spaces inside of them.

The first and second Text string blocks look the same. The first one is empty and the second contains 1 space character.

The other Text string blocks contain respectively 2,3,4 and 5 spaces.

image

This a Join block

image

With it you can join other text, variables, calculation results, etc, etc and display it for instance in a label.

Some samples of the use of the Join block you can see here.

By default you get a Join block with two sockets. If you want more you can use the white gear symbol in the little blue square on the top left of the Join block.

Peek 2020-06-05 10-24

You can use the white gear symbol to add but also to remove sockets.

So you could end up with a Join block looking like this. But this Join block just displays the Text string block that is behind it and nothing further.

image

This is the Length block

image

It returns the number of characters in the blok that is attached to it.

When you also use the Join block you can see that it adds all values of the attached Text string blocks together. Number blocks are treated the same way as Text string blocks.

This is the is Empty block

image

It will detect if the attached blocks are empty.

Some samples how you can use it.

The first result is false since the Text string block contains characters.

The second result is true since the Text string block is empty.

The third result is false since the Text string block contains a space character.

This is the is string block

image

With this block you can test if the block that is connected to it contains a string. For example.

As you can see you have to add a block, for instance a Text string block or variable that contains a Text string block with letters and/or numbers. If you use a Number block with the same content as a Text string block, the Number block will give a false in return and the Text string block true.

This is the compare texts block

Selection_999(1244)

The dropdown menu shows 4 options

image

> means greater then
< means smaller then
= means equal to
means not equal to

From the docs:

A string a considered lexicographically greater than another if it is alphabetically greater than the other string. Essentially, it would come after it in the dictionary. All uppercase letters are considered smaller or to occur before lowercase letters. cat would be > Cat.

To show this in examples.

CAT < cat is true because UPPERCASE goes before lowercase.
CAT ≠ cat is true because CAT is not equal to cat.
CAT = cat is false because CAT is not equal to cat.
CAT > cat is false because CAT is smaller than cat.

This is the trim block

Selection_999(1246)

It removes all spaces from the beginning and end of a string. The below Text string block contains a string with 5 spaces in the front and 5 spaces at the end.

Selection_999(1247)

When you add the trim block and execute it.

Selection_999(1249)

You get the following result.

Selection_999(1248)

You can see all spaces are removed.

this is the make UPPERCASE or lowercase block

Selection_999(1251)

It has two options.

Selection_999(1252)

It works like this. You connect a string and it converts it to either UPPERCASE or lowercase.

Selection_999(1253)

This is the start at text block.

image

It shows on what position in the string the text start that you are looking for.

Several examples:
image

The “B” is found at position 2. The “b” is not in the text so it gets the index 0.

The last example show the combination of the start at text block and the upcase block.

The piece string can contain more then one character.

image

This is the contains text block

Selection_999(1257)

It gives a true or false if the piece of text you want to find is or is not in the text you are searching.

Several examples.

The piece string can contain more then one character.

This is the split text block

Selection_999(1286)

Using the dropdown menu you can see it has 4 different options.

Selection_999(1287)

split

If you pass the block a string you can tell it where to split it. In the first case it splits the text at every occurence of the character “,”. In the second case it splits the string at the occurence of every letter “b”.

You can see what the result is. I will now use a block from the Lists category.

The split blocks generates a list in this case ( a b c)
When you want to pick the first item of that list you use the blue list block as shown.

You can split a word and put it in a list by putting an empty text string block.

Selection_999(1301)

The empty-string is something that has to do with the way Kodular is made and is related to java as far as i know. This has the following result when you want to call items in the list you generated.

When you select item 1 you get your empty string. When you select item 2 you get the first item of the string you split.

Selection_999(1299)

split at first

image

This blocks splits a string at the first occurence of a certain character. In the example the character “,” is used.

image

The textstring is split at the first “,”. So you get a list with one item “a”, and a second item “b,c”. The character that is used to split the string is omitted from the result.

split at any

image

With this block you can split a string with a number of different strings. In previous split blocks you were always limited to one split string. Now you can use multiple. The split strings are put in a make list block.

In the example below the string is split with the use of the character “,” and “|”.
You can see the result.

image

split at first of any

image

With this block you split a string in two at the first occurrence of one of the provided split strings that are in the make list block.

image

In the sample above you can see that the ", " character is the first one to be found so it is split.

You get a list that has two items. The first one is “a”, the second one “b,c,|d|e|f”.
The character that is used to split the string is omitted from the result.

This is the split at spaces block

image

It lets you split a textstring where the items are divided by spaces. The items are placed in a list.

image

The same thing can be done with these blocks. The Text string lock connected at the make a list block contains a space character.

image

This is the segment text block

Selection_999(1302)

When this block you can get a segment of a string. You have to set a starting point and how long the segment should be.

image

If the length number exceeds the length of the string that is tested you will get an error message. At least you get one in the companion.

This is the replace all text block

image

With this block you can replace a part of a string. Segment is the part to be replaced. Replacement is the part that will be used.

image

This is the obfuscated text block

image

From the documentation:

Produces text, like a text block. The difference is that th etext is not easily discoverable by examining the app’s contents. Use this when creating apps to distribute that include confidential information, for example, API keys.

Warning: This provides only very low security against expert adversaries.

This is the reverse block

image

This block reverses the string you attach to it.

image

This is the replace all mappings block.

This is a bit hard to explain. You have to use dictionary blocks with it.

With it you can replace text in a string using dictionary blocks.

You have two options when you click the dropdown menu.

image

Dictionary order

From the documentation:

If the dictionary order is specified, in the case of one key entry being a substring of another key entry, the first one to be replaced is based on the entry order in the dictionary (the earliest one gets replaced first).

In short: replace by element order in dictionary

Longest string first order

If the longest string order is specified, in the case of one key entry being a substring of another key entry, the first one to be replaced is the one which is longer.

In short: replace longest first, then replace the shorter substrings in order of string length

63 Likes

Nice Guide for Beginners.

4 Likes

Good and beautiful tutorial. I hope this is just the beginning. :ok_hand: :golfing_man:

3 Likes

Added some more blocks. Wanting to do this for a long time. Happy that I started and it is fun to do. :crazy_face:

8 Likes

Peter’s guide is better than docs for beginners :sunglasses:

11 Likes

Yes, absolutely right!

In docs only information about respective block is given, instead of that it will be better if there should be full information about how to use that block with different ways, as @Peter explained.

3 Likes

All textblocks are in the Beginner’s guide. Tell me what you think? Are there errors that i should fix?

2 Likes

great guide, which additionally shows how important it is to use the Do it feature,
see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Taifun

4 Likes

One correction here, should be two :slight_smile:
Also, 40 edits! :scream:

1 Like

Maybe it was an error on my side. OP of last post didn’t do anything wrong.

It is certainly being one of the best tutorials! Congratulations !

1 Like

Really nice post @Peter, it was so detailed and informative. In the end I was looking is there anything else because the whole topic was so interesting.

Thanks for your efforts.

1 Like

Really today I learned a lot about this guide.

Thank you.

3 Likes

Using replace mapping preferring dictionary order, if some of the text doesn’t exist in dictionary, what would it returns?

Maybe you can test that and show the result here. :wink:

2 Likes

Definitely! Will do it when available :slightly_smiling_face:

1 Like

How to remove a segment from a text starts from word :one" … to word “three” in a text like this:
“one two three four five six”
To get
“four five six”

You can use devices utilities parse method.

Text = Your text
Starts = " three "
ends = “”
if not found = (Any string)

It might works. If not, you can join some special characters after the text and type the characters to the “ends” parameter.

Second method using replace text.
replace text = you text
segment = "one two three "
replacement = “”

3 Likes

You could use the split text at block image. Plug in three. It will result in a list.

Then use image with index 2 to get

1 Like

How do I get just a certain amount of letters?

Example: I have a list with 5 names, each name contains 15 letters, then I just want you to show 6 letters and then the three points.

How is it:
Real Estate

How I wanted it to look:
Casa “Imob …”