Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda