试图从字符串中提取一个单词,在谷歌脚本中,在谷歌表单上.不熟悉语言,无法使功能正常工作



我是一个普通的C族,在谷歌表单项目中,我很难理解谷歌脚本。我想将一块文本复制/粘贴到单元格(1,1(中,按下一个按钮,然后从该字符串中提取数据,并将其变成一个漂亮的表。只是解析字符串时遇到问题。。。我的想法是搜索单词"DUG",然后给我后面的单词。

blob的格式为:垃圾垃圾DUG用户名垃圾DUG用户号码垃圾DUG域名垃圾DUG Usernumber(etc etc(。

问题是:我可以找到单词DUG的第一个实例,但我似乎无法在那个位置截断字符串。我听说过使用left((、right((或mid((,但据说这些函数并不存在。我好像错过了一些简单的东西。有关于套索的建议吗?非常感谢!

// function runs when button is clicked
function SortCustomerList() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var sheetName = spreadsheet.getName();
var pastedDataRange = spreadsheet.getRange(1, 1);                // location of the pasted data
var pastedData = pastedDataRange.getValue();                     //     get the data from that cell
var pastedText = pastedData.toString();                          //     convert that data into a string
// returns an index location of where "DUG" starts in the string
var foundLoc = pastedText.indexOf("DUG");                        

// show me that location for testing (number. int?) ***works!!***
spreadsheet.getRange(4, 1).activate();
spreadsheet.getCurrentCell().setValue(foundLoc);                 


// i want to chop the string at "DUG", show me everything to the right, starting where you found "DUG"
// ****doesnt work. returns the entire paste, not chopped
spreadsheet.getRange(10, 1).activate();            
spreadsheet.getCurrentCell().setValue(pastedText.split(foundLoc));        



// future:  rather than the rest of the string, just give me the word after "DUG"
//          set index (foundLoc) to AFTER the "DUG Username", to find the next instance of "DUG"
//          loop it, until there are no more instances of the word "DUG"
//          put it into pretty rows and columns

spreadsheet.getRange(5, 1).activate();
spreadsheet.getCurrentCell().setValue('Test Ran!');
};

看起来我需要的工具是substring((。只需将split((替换为substring((,它就会"正常工作"。感谢帮助过我的朋友,也感谢大家多年来对我的帮助。干杯

最新更新