File to ASCII with JavaScript. Read text file with JavaScript

  • File to ASCII with JavaScript. Read text file.

read_file.htm

<script>
    my_file = AppInventor.getWebViewString(); // INPUT
fetch(my_file).then(function (res) {
    /* get the data as a Blob */
    if (!res.ok) throw new Error("fetch failed");
    return res.arrayBuffer();
})
.then(function (ab) {
    var data = new Uint8Array(ab);
	// AppInventor.setWebViewString("" + data); // OUTPUT - GET ASCII
	var str = new TextDecoder().decode(Uint8Array.from(data));
	   AppInventor.setWebViewString("" + str); // OUTPUT
});
</script>

javascript_texto2

p70C_lee_archivo_javascipt.aia (2.5 KB)

oooooooooooooooooooooooooooooooooo
With this line, get ASCII:

AppInventor.setWebViewString("" + data); // OUTPUT - GET ASCII

Test File with extended ASCII 437 chars:
texto.txt

El - Ñandú - corrió por Cádiz. "Año" #2022#.

2 Likes