Read a file character by character/UTF8: Difference between revisions
Read a file character by character/UTF8 (view source)
Revision as of 18:00, 14 March 2020
, 4 years agoRename Perl 6 -> Raku, alphabetize, minor clean-up
(jq) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 40:
return EXIT_SUCCESS;
}</lang>
=={{header|Common Lisp}}==▼
{{works with|CLISP}}{{works with|Clozure CL}}{{works with|CMUCL}}{{works with|ECL (Lisp)}}{{works with|SBCL}}{{works with|ABCL}}▼
<lang lisp>;; CLISP puts the external formats into a separate package▼
#+clisp (import 'charset:utf-8 'keyword)▼
(with-open-file (s "input.txt" :external-format :utf-8)▼
(loop for c = (read-char s nil)▼
while c▼
do (format t "~a" c)))</lang>▼
=={{header|C sharp|C#}}==
Line 81 ⟶ 70:
}
}</lang>
▲=={{header|Common Lisp}}==
▲{{works with|CLISP}}{{works with|Clozure CL}}{{works with|CMUCL}}{{works with|ECL (Lisp)}}{{works with|SBCL}}{{works with|ABCL}}
▲<lang lisp>;; CLISP puts the external formats into a separate package
▲#+clisp (import 'charset:utf-8 'keyword)
▲(with-open-file (s "input.txt" :external-format :utf-8)
▲ (loop for c = (read-char s nil)
▲ while c
▲ do (format t "~a" c)))</lang>
=={{header|Déjà Vu}}==
Line 366:
}
}</lang>
=={{header|Lua}}==
Line 431 ⟶ 430:
{{out}}
𝄞 A ö Ж € 𝄞 Ε λ λ η ν ι κ ά y ä ® € 成 长 汉
=={{header|M2000 Interpreter}}==
from revision 27, version 9.3, of M2000 Environment, Chinese 长 letter displayed in console (as displayed in editor)
Line 712:
got character ⼥ [U+2f25]
</pre>
=={{header|Perl 6}}==▼
Perl 6 has a built in method .getc to get a single character from an open file handle. File handles default to UTF-8, so they will handle multi-byte characters correctly. ▼
To read a single character at a time from the Standard Input terminal; $*IN in Perl 6:▼
<lang perl6>.say while defined $_ = $*IN.getc;</lang>▼
Or, from a file:▼
<lang perl6>my $filename = 'whatever';▼
my $in = open( $filename, :r ) orelse .die;▼
print $_ while defined $_ = $in.getc;</lang>▼
=={{header|Phix}}==
Line 905 ⟶ 892:
(display c))
</lang>
(formerly Perl 6)
▲Perl 6 has a built in method .getc to get a single character from an open file handle. File handles default to UTF-8, so they will handle multi-byte characters correctly.
▲To read a single character at a time from the Standard Input terminal; $*IN in Perl 6:
▲<lang perl6>.say while defined $_ = $*IN.getc;</lang>
▲Or, from a file:
▲<lang perl6>my $filename = 'whatever';
▲my $in = open( $filename, :r ) orelse .die;
▲print $_ while defined $_ = $in.getc;</lang>
=={{header|REXX}}==
===version 1===
Line 995 ⟶ 997:
® C2AE
€ E282AC
EOF 454F46</pre>
=={{header|Ring}}==
|