Search code examples
google-app-maker

How to display just first few characters from a string


I have a field in the database for Name and for LastName, then I have a page with a label intended to display the full name.

I can display the full name in this page by binding the label to:

@datasource.item.Name + '.' + @datasource.item.LastName

(an example output would be: John.Richarson)

BUT, I instead of displaying the full name and last name, I just want to display the first three characters of the Name and LastName (In this example, I would like to display: Joh.Ric)

How can I define it in the binding properties? Thank you.


Solution

  • Since you can use a lot of the Javascript functions like .join() and .slice(), etc., I would suggest incorporating that into your binding. The only thing to remember is that when using a binding in conjunction with a Javascript function, the binding itself needs to be inside parenthesis. So:

    (@datasource.item.Name).slice(0,3) + '.' + (@datasource.item.LastName).slice(0,3)