Google Apps Script – How to Get a Substring from a Cell in Google Sheets

google sheetsgoogle-apps-script

How do I get a substring from a cell in Google Apps Script?

I'm trying to retrieve some data from a website.
I've already got the whole HTML code
and put it into a cell (thou it could be better put into a String variable)

I'm stuck in a simpler task:
How do I get the part of that cell/string I'm interested in,
(since I know it is always located in the same position/offset)

I tried string.substring(offset, length)
but it doesn't work.

How can I do that?
Help appreciated.

Best Answer

The string.substring(offset, length) works for me.

Let me show you:

var alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var letra = "";
letra = alfabeto.substring(0,1);

Result: letra = A