Cut text length by number of spaces

Hello family, I want to show the name of my user in the sidebar of my application, but there is a problem:

What if my username is very long and, well, it can be seen very crowded?

What I want to do to solve this problem is to tell it that from the text extension that it brought from the name, cut the text to the second space. so that you can take the first and middle names or even the first and last names (it depends on what the user enters when registering)

How can I make it take the text up to the second space, so that in a certain way the text can be cropped without being able to see a lot due to having fixed characters?

but instead of thinking in this way why dont you limit the user name with certain length?
image

1 Like

@Still-learning your solution only hides the software keyboard. At least disable the TextBox to be safer. Although I could, for example, paste a text with 13+ characters into the TextBox and continue typing an arbitrarily long text.


OP, it might not be enough to split at spaces - Someone could feed an arbitrarily long name into the system. You might want to separate the First Name / Last Name / etc. fields, and have individual length checks. Alternatively,

when TextBoxn.Text Changed {
    parts = split at spaces(TextBoxn.Text);
    for each part in list(parts) {
        if length(part) > 8 {
            // let the user know that they can't use such a long name
        }
    }
}
2 Likes

Hello, thanks for your answer: I couldn’t, because I get the name that the user has in his google account. I use firebase authentication.

Thanks for your input, but your blocks have a problem with this issue. What happens if, upon reaching those 18 characters, it cuts the surname in half or cuts the incomplete text, making the name meaningless.

I found a solution:

imagen

First I define a variable that replaces the text of the name for this example.

Now I tell him to separate by spaces and to put the list that he creates in the data variable.

It only remains to print the name and I do it by joining the first item (name) and the second item (surname) and I separate them by a space with the help of the empty text block that contains a space given by me.

Ready, in the name variable is the first name and the first surname.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.