Terminal control/Display an extended character: Difference between revisions
m (Added the Sidef language) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(50 intermediate revisions by 27 users not shown) | |||
Line 1: | Line 1: | ||
{{task|Text processing}} |
{{task|Text processing}} |
||
The task is to display an extended (non ASCII) character onto the terminal. For this task, we will display a £ (GBP currency sign). |
|||
;Task: |
|||
Display an extended (non ASCII) character onto the terminal. |
|||
Specifically, display a <big> £ </big> (GBP currency sign). |
|||
<br><br> |
|||
=={{header|11l}}== |
|||
<syntaxhighlight lang="11l">print(‘£’)</syntaxhighlight> |
|||
=={{header|ACL2}}== |
=={{header|ACL2}}== |
||
< |
<syntaxhighlight lang="lisp">(cw "£")</syntaxhighlight> |
||
=={{header|Action!}}== |
|||
<syntaxhighlight lang="action!">PROC Main() |
|||
BYTE CHBAS=$02F4 ;Character Base Register |
|||
CHBAS=$CC ;set the international character set |
|||
Position(2,2) |
|||
Put(8) ;print the GBP currency sign |
|||
RETURN</syntaxhighlight> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Display_an_extended_character.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
£ |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO; |
||
with Ada.Characters.Latin_1; |
with Ada.Characters.Latin_1; |
||
Line 13: | Line 35: | ||
begin |
begin |
||
Put(Ada.Characters.Latin_1.Pound_Sign); |
Put(Ada.Characters.Latin_1.Pound_Sign); |
||
end Pound;</ |
end Pound;</syntaxhighlight> |
||
Ada allows Unicode characters in the source, and provides output functions on "wide characters". |
Ada allows Unicode characters in the source, and provides output functions on "wide characters". |
||
< |
<syntaxhighlight lang="ada">with Ada.Wide_Text_IO; use Ada.Wide_Text_IO; |
||
procedure Unicode is |
procedure Unicode is |
||
begin |
begin |
||
Put("札幌"); |
Put("札幌"); |
||
end Unicode;</ |
end Unicode;</syntaxhighlight> |
||
=={{header|Arturo}}== |
|||
<syntaxhighlight lang="rebol">print "£"</syntaxhighlight> |
|||
{{out}} |
|||
<pre>£</pre> |
|||
=={{header|AutoHotkey}}== |
|||
<syntaxhighlight lang="autohotkey">msgbox % chr(163)</syntaxhighlight> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Line 28: | Line 62: | ||
You can print a literal "£". |
You can print a literal "£". |
||
< |
<syntaxhighlight lang="awk">BEGIN { print "£" }</syntaxhighlight> |
||
You can print a "£" using the escape sequences that match the encoding of your terminal. |
You can print a "£" using the escape sequences that match the encoding of your terminal. |
||
Line 49: | Line 83: | ||
|} |
|} |
||
< |
<syntaxhighlight lang="awk">BEGIN { print "\302\243" } # if your terminal is utf-8</syntaxhighlight> |
||
=={{header|BaCon}}== |
|||
<syntaxhighlight lang="freebasic">' Display extended character, pound sterling |
|||
LET c$ = UTF8$(0xA3) |
|||
PRINT c$</syntaxhighlight> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
=== |
==={{header|Applesoft BASIC}}=== |
||
Poke the glyph onto the hi-res screen. |
Poke the glyph onto the hi-res screen. |
||
< |
<syntaxhighlight lang="basic">10 DATA 56,68,4,14,4,4,122,0 |
||
20 HGR |
20 HGR |
||
30 FOR I = 8192 TO 16383 STEP 1024 |
30 FOR I = 8192 TO 16383 STEP 1024 |
||
40 READ B: POKE I,B: NEXT</ |
40 READ B: POKE I,B: NEXT</syntaxhighlight> |
||
=== |
==={{header|BASIC256}}=== |
||
<syntaxhighlight lang="freebasic">print "£" |
|||
# or |
|||
print chr(163)</syntaxhighlight> |
|||
==={{header|IS-BASIC}}=== |
|||
<syntaxhighlight lang="is-basic">PRINT "£"</syntaxhighlight> |
|||
or |
|||
<syntaxhighlight lang="is-basic">PRINT CHR$(35)</syntaxhighlight> |
|||
==={{header|QBasic}}=== |
|||
<syntaxhighlight lang="qbasic">PRINT "£" |
|||
' or |
|||
PRINT CHR$(156) |
|||
END</syntaxhighlight> |
|||
==={{header|True BASIC}}=== |
|||
<syntaxhighlight lang="qbasic">PRINT "£" |
|||
! or |
|||
PRINT CHR$(163) |
|||
END</syntaxhighlight> |
|||
==={{header|ZX Spectrum Basic}}=== |
|||
The ZX Spectrum uses a modified ascii character set that has a uk pound sign at character number 96: |
The ZX Spectrum uses a modified ascii character set that has a uk pound sign at character number 96: |
||
<lang |
<syntaxhighlight lang="basic">10 PRINT CHR$(96);</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
You can print a literal £ if it is available in the default ANSI code page: |
You can print a literal £ if it is available in the default ANSI code page: |
||
< |
<syntaxhighlight lang="bbcbasic"> PRINT "£"</syntaxhighlight> |
||
But to be on the safe side you can do this: |
But to be on the safe side you can do this: |
||
< |
<syntaxhighlight lang="bbcbasic"> VDU 23,22,640;512;8,16,16,128+8 : REM Enable UTF-8 mode |
||
PRINT CHR$(&C2) CHR$(&A3) : REM UTF-8 encoding for £</ |
PRINT CHR$(&C2) CHR$(&A3) : REM UTF-8 encoding for £</syntaxhighlight> |
||
=={{header|bc}}== |
=={{header|bc}}== |
||
You can print a literal "£". |
You can print a literal "£". |
||
< |
<syntaxhighlight lang="bc">"£ |
||
" |
" |
||
quit</ |
quit</syntaxhighlight> |
||
=={{header|beeswax}}== |
|||
<syntaxhighlight lang="beeswax">_4~9P.P.M}</syntaxhighlight> |
|||
=={{header|Befunge}}== |
=={{header|Befunge}}== |
||
Line 83: | Line 159: | ||
Example output of a pound character in Code page 437: |
Example output of a pound character in Code page 437: |
||
< |
<syntaxhighlight lang="befunge">"| "+,@</syntaxhighlight> |
||
Example output of a pound character in ISO-8859-1: |
Example output of a pound character in ISO-8859-1: |
||
< |
<syntaxhighlight lang="befunge">"%~"+,@</syntaxhighlight> |
||
=={{header|Bracmat}}== |
=={{header|Bracmat}}== |
||
<lang |
<syntaxhighlight lang="bracmat">put$£</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|AWK}} |
{{trans|AWK}} |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
int |
int |
||
Line 101: | Line 177: | ||
puts("\302\243"); /* if your terminal is utf-8 */ |
puts("\302\243"); /* if your terminal is utf-8 */ |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C sharp}}== |
=={{header|C sharp}}== |
||
< |
<syntaxhighlight lang="csharp">class Program |
||
{ |
{ |
||
static void Main() |
static void Main() |
||
Line 110: | Line 186: | ||
System.Console.WriteLine("£"); |
System.Console.WriteLine("£"); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>£</pre> |
<pre>£</pre> |
||
Line 116: | Line 192: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
int main() |
int main() |
||
Line 122: | Line 198: | ||
std::cout << static_cast<char>(163); // pound sign |
std::cout << static_cast<char>(163); // pound sign |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="clojure">(println "£")</syntaxhighlight> |
||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
{{works with|OpenCOBOL}} |
{{works with|OpenCOBOL}} |
||
< |
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. Display-Pound. |
PROGRAM-ID. Display-Pound. |
||
Line 137: | Line 213: | ||
GOBACK |
GOBACK |
||
.</ |
.</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
< |
<syntaxhighlight lang="lisp"> |
||
(format t "札幌~%") |
(format t "札幌~%") |
||
(format t "~C~%" (code-char #x00A3)) |
(format t "~C~%" (code-char #x00A3)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
Assuming unicode support on the terminal |
Assuming unicode support on the terminal |
||
< |
<syntaxhighlight lang="d">import std.stdio; |
||
void main() { |
void main() { |
||
writeln('\u00A3'); |
writeln('\u00A3'); |
||
}</ |
}</syntaxhighlight> |
||
<pre>£</pre> |
<pre>£</pre> |
||
=={{header|Dc}}== |
|||
Assuming unicode support on the terminal |
|||
<syntaxhighlight lang="dc">49827 P</syntaxhighlight> |
|||
=={{header|EchoLisp}}== |
|||
<syntaxhighlight lang="scheme"> |
|||
;; simplest |
|||
(display "£") |
|||
;; unicode character |
|||
(display "\u00a3") |
|||
;; HTML special character |
|||
(display "£") |
|||
;; CSS enhancement |
|||
(display "£" "color:blue;font-size:2em") |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<span style="color:blue;font-size:2em"> |
|||
£ |
|||
</span> |
|||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Line 167: | Line 263: | ||
The emerging ANS Forth 20xx standard includes an XCHAR wordset which allows manipulation of non-ASCII character sets such as Unicode. |
The emerging ANS Forth 20xx standard includes an XCHAR wordset which allows manipulation of non-ASCII character sets such as Unicode. |
||
< |
<syntaxhighlight lang="forth">163 xemit \ , or |
||
s" £" type</ |
s" £" type</syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="freebasic">Print Chr(156)</syntaxhighlight> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 177: | Line 278: | ||
func main() { |
func main() { |
||
fmt.Println("£") |
fmt.Println("£") |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<syntaxhighlight lang="haskell"> |
|||
<lang Haskell> |
|||
module Main where |
module Main where |
||
main = do |
main = do |
||
putStrLn "£" |
putStrLn "£" |
||
putStrLn "札幌" |
putStrLn "札幌" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Line 191: | Line 292: | ||
Write a given character number, say '163', using <code>char</code> to convert the integer into a string. |
Write a given character number, say '163', using <code>char</code> to convert the integer into a string. |
||
<syntaxhighlight lang="icon"> |
|||
<lang Icon> |
|||
procedure main () |
procedure main () |
||
write ("£ " || char (163)) # £ |
write ("£ " || char (163)) # £ |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j"> '£' |
||
£ |
£ |
||
'札幌' |
'札幌' |
||
札幌</ |
札幌</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">import java.io.PrintStream; |
||
import java.io.UnsupportedEncodingException; |
import java.io.UnsupportedEncodingException; |
||
Line 215: | Line 316: | ||
writer.println("札幌"); |
writer.println("札幌"); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
''Also works with gojq and with jaq'' |
|||
<syntaxhighlight lang="jq"> |
|||
"£" |
|||
</syntaxhighlight> |
|||
or at the command-line: |
|||
<syntaxhighlight lang="bash"> |
|||
jq -rn '"£"' |
|||
</syntaxhighlight> |
|||
or, using the symbol's codepoint: |
|||
<syntaxhighlight lang="bash"> |
|||
jq -nr '[163]|implode' |
|||
</syntaxhighlight> |
|||
or: |
|||
<syntaxhighlight lang="bash"> |
|||
jq -nr '"\u00a3"' |
|||
</syntaxhighlight> |
|||
=={{header|Julia}}== |
|||
{{trans|C}} |
|||
<syntaxhighlight lang="julia">println("£") |
|||
println("\302\243"); # works if your terminal is utf-8 |
|||
</syntaxhighlight> |
|||
=={{header|Kotlin}}== |
|||
<syntaxhighlight lang="scala">// version 1.1.2 |
|||
fun main(args:Array<String>) = println("£")</syntaxhighlight> |
|||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
<lang |
<syntaxhighlight lang="lasso">stdout(' £ ')</syntaxhighlight> |
||
Result: |
Result: |
||
<pre> £ </pre> |
<pre> £ </pre> |
||
Line 225: | Line 355: | ||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
<lang |
<syntaxhighlight lang="locobasic">10 PRINT CHR$(163)</syntaxhighlight> |
||
=={{header|Lua}}== |
|||
Lua requires an extension module for UTF-8 support. However, the '£' symbol specified for this task is part of extended ASCII (codes 128 - 255) which can be accessed in the same way as normal ASCII. |
|||
<syntaxhighlight lang="lua">print(string.char(156))</syntaxhighlight> |
|||
=={{header|M2000 Interpreter}}== |
|||
<syntaxhighlight lang="m2000 interpreter"> |
|||
Print chrcode$(163), "£", chrcode$(127968), "🏠" |
|||
</syntaxhighlight> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
<lang |
<syntaxhighlight lang="mathematica">FromCharacterCode[{163}]</syntaxhighlight> |
||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
< |
<syntaxhighlight lang="netrexx">/* NetRexx */ |
||
options replace format comments java crossref symbols binary |
options replace format comments java crossref symbols binary |
||
Line 246: | Line 384: | ||
say (Rexx GBP).d2c |
say (Rexx GBP).d2c |
||
return |
return |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 255: | Line 393: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">echo "£" |
||
echo "札幌" |
echo "札幌" |
||
import unicode |
import unicode |
||
echo Rune(0xa3)</ |
echo Rune(0xa3)</syntaxhighlight> |
||
=={{header|Objeck}}== |
|||
<syntaxhighlight lang="objeck">class Program { |
|||
function : Main(args : String[]) ~ Nil { |
|||
"£"->PrintLine(); |
|||
} |
|||
}</syntaxhighlight> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
< |
<syntaxhighlight lang="pascal">program pound; |
||
uses crt; |
uses crt; |
||
begin |
begin |
||
write(chr( 163 )); |
write(chr( 163 )); |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Perl}}== |
|||
<syntaxhighlight lang="perl">use feature 'say'; |
|||
# OK as is |
|||
say '£'; |
|||
# these need 'binmode needed to surpress warning about 'wide' char |
|||
binmode STDOUT, ":utf8"; |
|||
say "\N{FULLWIDTH POUND SIGN}"; |
|||
say "\x{FFE1}"; |
|||
say chr 0xffe1;</syntaxhighlight> |
|||
=={{header|Phix}}== |
|||
On Windows (Linux should be fine), you may need to set the terminal to a truetype font (eg Lucida Console) and the code page to CP_UTF8 (chcp 65001).<br> |
|||
See demo\HelloUTF8.exw for a (not very pretty) way to do that programmaticaly.<br> |
|||
The following assumes you have done that manually, and saved the source code file in UTF-8 format. |
|||
<!--<syntaxhighlight lang="phix">(phixonline)--> |
|||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"£"</span><span style="color: #0000FF;">)</span> |
|||
<!--</syntaxhighlight>--> |
|||
Output: |
|||
<pre>£</pre> |
|||
=={{header|Picat}}== |
|||
<syntaxhighlight lang="picat">go => |
|||
println("£"), |
|||
println(chr(163)), |
|||
println("太極拳"), % Tàijíquán |
|||
nl.</syntaxhighlight> |
|||
{{out}} |
|||
<pre>£ |
|||
£ |
|||
太極拳</pre> |
|||
=={{header|Perl 6}}== |
|||
To demonstrate we're not limited to Latin-1, we'll print the fullwidth variant. |
|||
<lang Perl 6>say '£'; |
|||
say "\x[FFE1]"; |
|||
say "\c[FULLWIDTH POUND SIGN]"; |
|||
0xffe1.chr.say;</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(prinl (char 26413) (char 24140)) # Sapporo </syntaxhighlight> |
||
Output: |
Output: |
||
<pre>札幌</pre> |
<pre>札幌</pre> |
||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang="pl/i"> declare pound character (1) static initial ('9c'x); |
||
put skip list (pound);</ |
put skip list (pound);</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
<lang |
<syntaxhighlight lang="purebasic">Print(Chr(163))</syntaxhighlight> |
||
<pre>£</pre> |
<pre>£</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Python 2: |
|||
<lang Python>print u'\u00a3'</lang> |
|||
<syntaxhighlight lang="python">print u'\u00a3'</syntaxhighlight> |
|||
<pre>£</pre> |
|||
Alternatively, as any Unicode character is legal in Python code: |
|||
<syntaxhighlight lang="python">£ = '£' |
|||
print(£)</syntaxhighlight> |
|||
<pre>£</pre> |
|||
=={{header|R}}== |
|||
<syntaxhighlight lang="r">cat("£")</syntaxhighlight> |
|||
{{out}} |
|||
<pre>£</pre> |
<pre>£</pre> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
(display "£") |
(display "£") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
To demonstrate we're not limited to Latin-1, we'll print the fullwidth variant. |
|||
<syntaxhighlight lang="raku" line>say '£'; |
|||
say "\x[FFE1]"; |
|||
say "\c[FULLWIDTH POUND SIGN]"; |
|||
0xffe1.chr.say;</syntaxhighlight> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX program demonstrates displaying an extended character (glyph) to the terminal.*/ |
||
/* [↓] this SAY will display the £ glyph (if the term supports it).*/ |
|||
say '£' /*this assumes the pound sign glyph is displayable on the terminal. */ |
|||
/*this program can execute correctly on an EBCDIC or ASCII machine.*/ |
|||
/*stick a fork in it, we're all done. */</syntaxhighlight> |
|||
{{out|output|text=:}} |
|||
<pre> |
|||
£ |
|||
</pre> |
|||
=={{header|Ring}}== |
|||
say d2c(163) /*assuming the pound sign is 163 on the display codepage*/</lang> |
|||
<syntaxhighlight lang="ring"> |
|||
# Project : Terminal control/Display an extended character |
|||
see "£" |
|||
</syntaxhighlight> |
|||
Output: |
|||
<pre> |
|||
£ |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">#encoding: UTF-8 #superfluous in Ruby > 1.9.3 |
||
puts "£"</ |
puts "£"</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}}< |
{{libheader|Scala}}<syntaxhighlight lang="scala">object ExtendedCharacter extends App { |
||
println("£") |
println("£") |
||
println("札幌") |
println("札幌") |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
A [http://seed7.sourceforge.net/libraries/console.htm#write%28ref_console_file,in_string%29 write] |
A [http://seed7.sourceforge.net/libraries/console.htm#write%28ref_console_file,in_string%29 write] |
||
to a [http://seed7.sourceforge.net/libraries/console.htm console] accepts Unicode characters.< |
to a [http://seed7.sourceforge.net/libraries/console.htm console] accepts Unicode characters.<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
include "console.s7i"; |
include "console.s7i"; |
||
Line 328: | Line 537: | ||
# the program waits until Return/Enter is pressed. |
# the program waits until Return/Enter is pressed. |
||
readln; |
readln; |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">say '£'; |
||
say "\x{FFE1}"; |
say "\x{FFE1}"; |
||
say "\N{FULLWIDTH POUND SIGN}"; |
say "\N{FULLWIDTH POUND SIGN}"; |
||
say 0xffe1.chr;</ |
say 0xffe1.chr;</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Provided the system encoding has a “£” symbol in it, this works: |
Provided the system encoding has a “£” symbol in it, this works: |
||
<lang |
<syntaxhighlight lang="tcl">puts \u00a3</syntaxhighlight> |
||
Tcl can output all unicode characters in the BMP, but only if the consumer of the output (terminal, etc.) is able to understand those characters in its current encoding will the output actually make sense. Strictly, this is not a limitation of Tcl but of the environment in which it is placed. |
Tcl can output all unicode characters in the BMP, but only if the consumer of the output (terminal, etc.) is able to understand those characters in its current encoding will the output actually make sense. Strictly, this is not a limitation of Tcl but of the environment in which it is placed. |
||
=={{header|Verilog}}== |
|||
<syntaxhighlight lang="verilog">module main; |
|||
initial begin |
|||
$display("£"); |
|||
end |
|||
endmodule</syntaxhighlight> |
|||
=={{header|Wren}}== |
|||
<syntaxhighlight lang="wren">System.print("£")</syntaxhighlight> |
|||
=={{header|Xidel}}== |
|||
http://videlibri.sourceforge.net/xidel.html |
|||
<syntaxhighlight lang="bash">xidel -s -e 'parse-html("£ or £")' |
|||
£ or £</syntaxhighlight> |
|||
<syntaxhighlight lang="bash">echo '"\u00a3"' | xidel -s - -e 'json($raw)' |
|||
£ |
|||
xidel -s -e 'json("""\\u00a3""")' --xquery 'json(""\\u00a3"")' |
|||
£ |
|||
£</syntaxhighlight> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">code ChOut=8; |
||
ChOut(0, $9C) \code for IBM PC's extended (OEM) character set |
ChOut(0, $9C) \code for IBM PC's extended (OEM) character set |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Yabasic}}== |
|||
<syntaxhighlight lang="freebasic">print chr$(156)</syntaxhighlight> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
If you output device support UTF-8 then: |
If you output device support UTF-8 then: |
||
< |
<syntaxhighlight lang="zkl">"\u00a3 \Ua3;".println() //-->£ £</syntaxhighlight> |
||
Revision as of 11:58, 13 February 2024
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Display an extended (non ASCII) character onto the terminal.
Specifically, display a £ (GBP currency sign).
11l
print(‘£’)
ACL2
(cw "£")
Action!
PROC Main()
BYTE CHBAS=$02F4 ;Character Base Register
CHBAS=$CC ;set the international character set
Position(2,2)
Put(8) ;print the GBP currency sign
RETURN
- Output:
Screenshot from Atari 8-bit computer
£
Ada
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1;
procedure Pound is
begin
Put(Ada.Characters.Latin_1.Pound_Sign);
end Pound;
Ada allows Unicode characters in the source, and provides output functions on "wide characters".
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
procedure Unicode is
begin
Put("札幌");
end Unicode;
Arturo
print "£"
- Output:
£
AutoHotkey
msgbox % chr(163)
AWK
You can print a literal "£".
BEGIN { print "£" }
You can print a "£" using the escape sequences that match the encoding of your terminal.
cp437 | "\234" |
---|---|
iso-8859-1 | "\243" |
euc-jp | "\241\362" |
utf-8 | "\302\243" |
gb18030 | "\201\60\204\65" |
BEGIN { print "\302\243" } # if your terminal is utf-8
BaCon
' Display extended character, pound sterling
LET c$ = UTF8$(0xA3)
PRINT c$
BASIC
Applesoft BASIC
Poke the glyph onto the hi-res screen.
10 DATA 56,68,4,14,4,4,122,0
20 HGR
30 FOR I = 8192 TO 16383 STEP 1024
40 READ B: POKE I,B: NEXT
BASIC256
print "£"
# or
print chr(163)
IS-BASIC
PRINT "£"
or
PRINT CHR$(35)
QBasic
PRINT "£"
' or
PRINT CHR$(156)
END
True BASIC
PRINT "£"
! or
PRINT CHR$(163)
END
ZX Spectrum Basic
The ZX Spectrum uses a modified ascii character set that has a uk pound sign at character number 96:
10 PRINT CHR$(96);
BBC BASIC
You can print a literal £ if it is available in the default ANSI code page:
PRINT "£"
But to be on the safe side you can do this:
VDU 23,22,640;512;8,16,16,128+8 : REM Enable UTF-8 mode
PRINT CHR$(&C2) CHR$(&A3) : REM UTF-8 encoding for £
bc
You can print a literal "£".
"£
"
quit
beeswax
_4~9P.P.M}
Befunge
There's no portable way to print an extended character in Befunge, since character output will typically use the default code page of the operating system or environment. On Windows this will often be Windows-1252 or ISO-8859-1 for GUI applications and Code page 437 for console applications (but that also likely depends on the OS localisation).
Example output of a pound character in Code page 437:
"| "+,@
Example output of a pound character in ISO-8859-1:
"%~"+,@
Bracmat
put$£
C
#include <stdio.h>
int
main()
{
puts("£");
puts("\302\243"); /* if your terminal is utf-8 */
return 0;
}
C#
class Program
{
static void Main()
{
System.Console.WriteLine("£");
}
}
Output:
£
C++
#include <iostream>
int main()
{
std::cout << static_cast<char>(163); // pound sign
return 0;
}
Clojure
(println "£")
COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. Display-Pound.
PROCEDURE DIVISION.
DISPLAY "£"
GOBACK
.
Common Lisp
(format t "札幌~%")
(format t "~C~%" (code-char #x00A3))
D
Assuming unicode support on the terminal
import std.stdio;
void main() {
writeln('\u00A3');
}
£
Dc
Assuming unicode support on the terminal
49827 P
EchoLisp
;; simplest
(display "£")
;; unicode character
(display "\u00a3")
;; HTML special character
(display "£")
;; CSS enhancement
(display "£" "color:blue;font-size:2em")
- Output:
£
Erlang
In Erlang a string is a list of integers. So the list of 196 is £.
- Output:
8> Pound = [163]. 9> io:fwrite( "~s~n", [Pound] ). £
Forth
The emerging ANS Forth 20xx standard includes an XCHAR wordset which allows manipulation of non-ASCII character sets such as Unicode.
163 xemit \ , or
s" £" type
FreeBASIC
Print Chr(156)
Go
package main
import "fmt"
func main() {
fmt.Println("£")
}
Haskell
module Main where
main = do
putStrLn "£"
putStrLn "札幌"
Icon and Unicon
Write a given character number, say '163', using char
to convert the integer into a string.
J
'£'
£
'札幌'
札幌
Java
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
public class Main
{
public static void main(String[] args) throws UnsupportedEncodingException
{
PrintStream writer = new PrintStream(System.out, true, "UTF-8");
writer.println("£");
writer.println("札幌");
}
}
jq
Also works with gojq and with jaq
"£"
or at the command-line:
jq -rn '"£"'
or, using the symbol's codepoint:
jq -nr '[163]|implode'
or:
jq -nr '"\u00a3"'
Julia
println("£")
println("\302\243"); # works if your terminal is utf-8
Kotlin
// version 1.1.2
fun main(args:Array<String>) = println("£")
Lasso
stdout(' £ ')
Result:
£
Locomotive Basic
10 PRINT CHR$(163)
Lua
Lua requires an extension module for UTF-8 support. However, the '£' symbol specified for this task is part of extended ASCII (codes 128 - 255) which can be accessed in the same way as normal ASCII.
print(string.char(156))
M2000 Interpreter
Print chrcode$(163), "£", chrcode$(127968), "🏠"
Mathematica/Wolfram Language
FromCharacterCode[{163}]
NetRexx
/* NetRexx */
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
GBP = '\u00a3' -- unicode code point
say GBP
GBP = '£' -- if the editor's up to it
say GBP
GBP = 16x00a3 -- yet another way
say (Rexx GBP).d2c
return
- Output:
£ £ £
Nim
echo "£"
echo "札幌"
import unicode
echo Rune(0xa3)
Objeck
class Program {
function : Main(args : String[]) ~ Nil {
"£"->PrintLine();
}
}
Pascal
program pound;
uses crt;
begin
write(chr( 163 ));
end.
Perl
use feature 'say';
# OK as is
say '£';
# these need 'binmode needed to surpress warning about 'wide' char
binmode STDOUT, ":utf8";
say "\N{FULLWIDTH POUND SIGN}";
say "\x{FFE1}";
say chr 0xffe1;
Phix
On Windows (Linux should be fine), you may need to set the terminal to a truetype font (eg Lucida Console) and the code page to CP_UTF8 (chcp 65001).
See demo\HelloUTF8.exw for a (not very pretty) way to do that programmaticaly.
The following assumes you have done that manually, and saved the source code file in UTF-8 format.
puts(1,"£")
Output:
£
Picat
go =>
println("£"),
println(chr(163)),
println("太極拳"), % Tàijíquán
nl.
- Output:
£ £ 太極拳
PicoLisp
(prinl (char 26413) (char 24140)) # Sapporo
Output:
札幌
PL/I
declare pound character (1) static initial ('9c'x);
put skip list (pound);
PureBasic
Print(Chr(163))
£
Python
Python 2:
print u'\u00a3'
£
Alternatively, as any Unicode character is legal in Python code:
£ = '£'
print(£)
£
R
cat("£")
- Output:
£
Racket
#lang racket
(display "£")
Raku
(formerly Perl 6) To demonstrate we're not limited to Latin-1, we'll print the fullwidth variant.
say '£';
say "\x[FFE1]";
say "\c[FULLWIDTH POUND SIGN]";
0xffe1.chr.say;
REXX
/*REXX program demonstrates displaying an extended character (glyph) to the terminal.*/
/* [↓] this SAY will display the £ glyph (if the term supports it).*/
say '£' /*this assumes the pound sign glyph is displayable on the terminal. */
/*this program can execute correctly on an EBCDIC or ASCII machine.*/
/*stick a fork in it, we're all done. */
- output :
£
Ring
# Project : Terminal control/Display an extended character
see "£"
Output:
£
Ruby
#encoding: UTF-8 #superfluous in Ruby > 1.9.3
puts "£"
Scala
object ExtendedCharacter extends App {
println("£")
println("札幌")
}
Seed7
A write
to a console accepts Unicode characters.
$ include "seed7_05.s7i";
include "console.s7i";
const proc: main is func
local
var text: console is STD_NULL;
begin
console := open(CONSOLE);
write(console, "£");
# Terminal windows often restore the previous
# content, when a program is terminated. Therefore
# the program waits until Return/Enter is pressed.
readln;
end func;
Sidef
say '£';
say "\x{FFE1}";
say "\N{FULLWIDTH POUND SIGN}";
say 0xffe1.chr;
Tcl
Provided the system encoding has a “£” symbol in it, this works:
puts \u00a3
Tcl can output all unicode characters in the BMP, but only if the consumer of the output (terminal, etc.) is able to understand those characters in its current encoding will the output actually make sense. Strictly, this is not a limitation of Tcl but of the environment in which it is placed.
Verilog
module main;
initial begin
$display("£");
end
endmodule
Wren
System.print("£")
Xidel
http://videlibri.sourceforge.net/xidel.html
xidel -s -e 'parse-html("£ or £")'
£ or £
echo '"\u00a3"' | xidel -s - -e 'json($raw)'
£
xidel -s -e 'json("""\\u00a3""")' --xquery 'json(""\\u00a3"")'
£
£
XPL0
code ChOut=8;
ChOut(0, $9C) \code for IBM PC's extended (OEM) character set
Yabasic
print chr$(156)
zkl
If you output device support UTF-8 then:
"\u00a3 \Ua3;".println() //-->£ £
- Programming Tasks
- Text processing
- 11l
- ACL2
- Action!
- Ada
- Arturo
- AutoHotkey
- AWK
- BaCon
- BASIC
- Applesoft BASIC
- BASIC256
- IS-BASIC
- QBasic
- True BASIC
- ZX Spectrum Basic
- BBC BASIC
- Bc
- Beeswax
- Befunge
- Bracmat
- C
- C sharp
- C++
- Clojure
- COBOL
- Common Lisp
- D
- Dc
- EchoLisp
- Erlang
- Forth
- FreeBASIC
- Go
- Haskell
- Icon
- Unicon
- J
- Java
- Jq
- Julia
- Kotlin
- Lasso
- Locomotive Basic
- Lua
- M2000 Interpreter
- Mathematica
- Wolfram Language
- NetRexx
- Nim
- Objeck
- Pascal
- Perl
- Phix
- Picat
- PicoLisp
- PL/I
- PureBasic
- Python
- R
- Racket
- Raku
- REXX
- Ring
- Ruby
- Scala
- Seed7
- Sidef
- Tcl
- Verilog
- Wren
- Xidel
- XPL0
- Yabasic
- Zkl
- Terminal control
- Axe/Omit