Reputation: 1
Using the following code to return a portion of a string:
function myFunction() {
var str = "";
var res = str.substr(44, 47);
Logger.log(res)
return res
}
When I go to use the function in a spreadsheet, it returns a blank. There is no error message associated. What do I need to change to return the portion of the string I am trying to isolate?
Upvotes: 0
Views: 518
Reputation: 1471
Your str is empty ,so you are returning an empty string. If you try the following, as a comparison, a substring is returned:
function myFunction() {
var str = "This is a string which is longer than forty seven characters long so it should give some output";
var res = str.substr(44, 47);
Logger.log(res)
return res
}
Upvotes: 1