Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How do you truncate a String to a max number of bytes in Google Apps Script?

I am parsing a JSON object obtained by URLFetchApp.fetch() and need to truncate a string value to a max number of bytes. It seems like some combination of the Google Apps Script Utilities Class and HTTPResponse Class is where I will find the answer, but I can not figure out which methods to use and how to put them together.

{object: {key: 'string'}}

something like:

object.key.string.toBytes().substringAsBytes(0,maxBytes).backToString()

https://developers.google.com/apps-script/reference/utilities

https://developers.google.com/apps-script/reference/url-fetch/http-response

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use with Array.splice:

const str = { obj: { key: 'string' } }.obj.key,
  maxBytes = 10,
  byteData = Utilities.newBlob(str).getBytes();
byteData.splice(maxBytes);
const truncatedStr = Utilities.newBlob(byteData).getDataAsString();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!