Read a file character by character/UTF8: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Promote to task, lots of examples, little controversy) |
(Added Wren) |
||
Line 1,130: | Line 1,130: | ||
<lang tcl>fconfigure $channel -buffersize $byteCount</lang> |
<lang tcl>fconfigure $channel -buffersize $byteCount</lang> |
||
When the channel is only being accessed from Tcl (or via Tcl's C API) it is not normally necessary to adjust this option. |
When the channel is only being accessed from Tcl (or via Tcl's C API) it is not normally necessary to adjust this option. |
||
=={{header|Wren}}== |
|||
<lang ecmascript>import "io" for File |
|||
File.open("input.txt") { |file| |
|||
var offset = 0 |
|||
var char = "" // stores each byte read till we have a complete UTF encoded character |
|||
while(true) { |
|||
var b = file.readBytes(1, offset) |
|||
if (b == "") return // end of stream |
|||
char = char + b |
|||
if (char.codePoints[0] >= 0) { // a UTF encoded character is complete |
|||
System.write(char) // print it |
|||
char = "" // reset store |
|||
} |
|||
offset = offset + 1 |
|||
} |
|||
}</lang> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |