Using JavaScript to truncate text to a certain size (8 KB)

后端 未结 4 1068
南笙
南笙 2021-01-12 05:57

I\'m using the Zemanta API, which accepts up to 8 KB of text per call. I\'m extracting the text to send to Zemanta from Web pages using JavaScript, so I\'m looking for a fun

4条回答
  •  天命终不由人
    2021-01-12 06:17

    No it's not safe to assume that 8KB of text is 8192 characters, since in some character encodings, each character takes up multiple bytes.

    If you're reading the data from files, can't you just grab the filesize? Or read it in in chunks of 8KB?

提交回复
热议问题