Google Apps Script: Basic Beginners Guide to Using Strings in Code

Google Apps Script, Javascript, strings

Hey there, Yagi here, you’ve probably stumbled across this page from a link from one of my other in-depth tutorials. This is just a quick primer on Javascript Strings in Google Apps Script for the non-coder.

Here’s a bare-bones example of how a string of text might come together in your code:

The resulting log would  look like this:

strings in Google Apps Script

 

Strings, +, \n and arrays[value]

If you are unfamiliar with basic string syntax and joining (concatenation), basically you can write text inside a single (‘) or double(“) quotation marks. For example:

To join two strings together you can concatenate them with a plus sign (+).

Just remember to put a space inside your quotation mars at the end if you are going to join another word or the words will not be spaced and theywillbealltogether.

This is handy when you want to put things on separate lines in your code but it won’t be on a separate line when it is displayed. You can use the newline escape sequence \n to return the next part of a string to a new line.

To insert a custom variable into a string, one fairly beginner-friendly approach is to put it between two plus signs.

You can see in the meatz variable above, we have put our two meat items in an array. An array always starts at zero (0). So to get chicken we would do, meatz[0].

Meow get on back to your main tutorial and get learn’n.

Create and Publish a Google Workspace Add-on with Apps Script Course

Need help with Google Workspace development?

My team of experts can help you with all of your needs, from custom app development to integrations and security. We have a proven track record of success in helping businesses of all sizes get the most out of Google Workspace.

Schedule a free consultation today to discuss your needs and get started or learn more about our services here.


~Yagi