You can join together as many strings as you like by clicking on the blue gear icon (also know as a block mutator) and manually add in extra items, where ever you want them.
You can use the length of block in your projects to measure the length of a string.
It takes a stings as an input and returns the number of characters in that string as an output.
Example 1
This first example is an alternative way of approaching the previous tip. Here, we measure the length of the string to see if the user has typed in anything or not. If the length is greater than 1 (most names tend to be two letters or more!) then the greeting is displayed in the label.
There are certain cases where you might want to make sure that a string has a certain minimum or maximum length.
For example, if you are asking your user to create a password, you might want to make sure that it is at least 6 characters long. The blocks below show how to do this.
In other cases, a password might have to be a minimum of 6 characters but a maximum of 32 characters in length.
You can check if it’s more then 5 and less than 33 character with the blocks below:
Lots of blocks, such as the and block in the example above, take internal inputs by default so they look like this: However, if the internal blocks get too long it can be difficult to read so you can change the shape of the block to accept external inputs instead, so it would look like this: NOTE we’re only changing the shape of the block here, the functionality of the block is completely unaffected.
In the previous example, if we right-click on the and block and choose “External Inputs” from the drop down menu…
The to UPPERCASE block is actually a text transform block that lets you choose whether you want to return an input string as “ALL UPPER CASE”, or as “all ower case” or as “All Title Case”, just click the little drop-down arrow to choose the option that suits your needs.
Similarly, the trim spaces from both sides block also has a selector so that you choose to remove spaces from both sides, from the left side only or from the right side only.
Example 1
In this scenario we are checking to see if a users password matches our password, which happens to be all lower case. Some keyboards can auto-correct or auto-capitalise text, and if your text input is just showing ***** to the user it can be very hard for them to spot this. Similarly, sometime a new space will be accidentally or automatically added and we want to trim these.
If you need to do this “trim and transform” operation in multiple places in your app, or if you want to tidy up multiple different text inputs for your user then you could create a dedicated function to do this:
As the name implies, the newline block allows you to put text onto a new line, i.e. it creates a line break in a string.
You can use as many newline blocks as you need to in your projects.
Example 1
In this first example we just put a line break in between the two strings. This means that “hello” is on the first line and “world” is below that on the second line.
Example 2
In this second example, you have a list of things and you want to display them all in a label. Rather than having all the items bunched together on a single line, you want each item to go on its own line.
It depends on the text parser I think, so using a dedicated block will give a consistent UX across all currently-supported versions of iOS and Android.
There are ways to do this mathematically but you can also convert the number to text by joining it with “” (an empty string) and then check the length.
If you prefer to use math, you could divide by 10 and check if the remainder is <, > or = to 0 and that will tell you the number of digits.