Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Spreadsheet Script working with strings

I have a question about how to work with 'string' type in Google Script?

I have a column with sites in different formats, e.g. http://testsite.com/, http://www.sitetest.net/, dot.anothersite.com, http://anysite.net/index.html and so on.

So I want to automatically format these records to one template: sitename.domain (for example http://testsite.com/ = testsite.com || http://www.sitetest.net/ = sitetest.net)

I get this info by this script:

var sheet = SpreadsheetApp.getActiveSheet();
  var sheetName = sheet.getName();
  var restrictSheet = "Summary";
  if (sheetName != restrictSheet){ // I don't need to modify first sheet from my spreadsheet
    var sheetRange = sheet.getActiveRange();
    var sData = sheet.getRange("A3:A"); // column with sites
    var TextArray = sData.getValues();
  }else Browser.msgBox("wrong sheet");
}

And I don't know how to work with strings in google script. In C++, for example, I could use string functions like String.Find() or String.Mid(). But I can't see equal functions in Google Scripts

like image 845
barnak Avatar asked Feb 25 '13 16:02

barnak


1 Answers

Well... I've found the answer on my own question :D

Google Script uses String class from JavaScript So functions and methods from JS works also in Google Scripts..

http://www.w3schools.com/jsref/jsref_obj_string.asp

May be it will help somebody.

like image 136
barnak Avatar answered Sep 22 '22 14:09

barnak