Home > Programming > Google Script

Google Script

I wanted to learn a little about Google Script. I discovered a site that has the vocabulary list from Latina Christiana I in a table in HTML. I was pleasantly surprised that this pasted nicely into a Google spreadsheet.

But the first column had extra stuff in it that I didn’t want in that column. Gee, I thought, wouldn’t it be nice to be able to just run a simple regular expression on that column to remove everything after the comma?

So yes, it is possible and really not very difficult to do. And here is my solution:

function stripAfterComma() {
 var range = SpreadsheetApp.getActiveRange();
 var values = range.getValues();
 var results = [];
 for( j in values ){
   var row = [];
   for( i in values[j] ){
     var new_value = values[j][i].match( /^[^,]*/ )[0];
     row.push(new_value);
   }
   results.push(row);
 }
 range.setValues( results );
}​

And Voila my spreadsheet can now be pasted into Quizlet and used to learn those vocabulary words. Have fun with the quiz.

Advertisement
Categories: Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.