Reputation: 9
[google-apps-script] Google script to extract the first word in a cell. I would like write a google script to extract the first word in a cell in a google spreadsheet.
For example if the cell contains, 'John White'. I would like to extract the word, 'John'.
Upvotes: 0
Views: 4385
Reputation: 745
Sure can! If you know what cell you want to reference and what you want to split them by you can easily create a function to find the first word in a cell.
function getCellWord(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange('A1:A1');
var wordArray = range.getValue().split(" "); //Split by space
Logger.log(wordArray[0]); // first word
Logger.log(wordArray[1]); // second word
Logger.log(wordArray[2]); // third word
}
Upvotes: 1