Terminal control/Display an extended character

From Rosetta Code
Task
Terminal control/Display an extended character
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[edit]

print(‘£’)

ACL2[edit]

(cw "£")

Action![edit]

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[edit]

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[edit]

print "£"
Output:
£

AutoHotkey[edit]

msgbox % chr(163)

AWK[edit]

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[edit]

' Display extended character, pound sterling
LET c$ = UTF8$(0xA3)
PRINT c$

BASIC[edit]

Applesoft BASIC[edit]

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[edit]

print "£"

# or

print chr(163)


IS-BASIC[edit]

PRINT "£"

or

PRINT CHR$(35)


QBasic[edit]

PRINT "£"

' or

PRINT CHR$(156)
END


True BASIC[edit]

PRINT "£"

! or

PRINT CHR$(163)
END


ZX Spectrum Basic[edit]

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[edit]

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[edit]

You can print a literal "£".


"
quit

beeswax[edit]

_4~9P.P.M}

Befunge[edit]

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[edit]

put$£

C[edit]

Translation of: AWK
#include <stdio.h>

int
main()
{
	puts("£");
	puts("\302\243"); /* if your terminal is utf-8 */
	return 0;
}

C#[edit]

class Program
{
    static void Main()
    {
        System.Console.WriteLine("£");
    }
}

Output:

£

C++[edit]

#include <iostream>

int main()
{
    std::cout << static_cast<char>(163); // pound sign
    return 0;
}

Clojure[edit]

(println "£")

COBOL[edit]

Works with: OpenCOBOL
       IDENTIFICATION DIVISION.
       PROGRAM-ID. Display-Pound.

       PROCEDURE DIVISION.
       DISPLAY "£"

       GOBACK
       .

Common Lisp[edit]

(format t "札幌~%")
(format t "~C~%" (code-char #x00A3))

D[edit]

Assuming unicode support on the terminal

import std.stdio;

void main() {
    writeln('\u00A3');
}
£

Dc[edit]

Assuming unicode support on the terminal

49827 P

EchoLisp[edit]

;; simplest
(display "£")
;; unicode character
(display "\u00a3")
;; HTML special character
(display "&pound;")
;; CSS enhancement
(display "£" "color:blue;font-size:2em")
Output:

£

Erlang[edit]

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[edit]

Works with: GNU Forth version 0.7.0

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[edit]

Print Chr(156)


Go[edit]

package main

import "fmt"

func main() {
    fmt.Println("£")
}

Haskell[edit]

module Main where
main = do
        putStrLn "£"
        putStrLn "札幌"

Icon and Unicon[edit]

Write a given character number, say '163', using char to convert the integer into a string.

procedure main ()
  write ("£ " || char (163)) # £
end

J[edit]

   '£'
£
   '札幌'
札幌

Java[edit]

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[edit]

Works with: 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[edit]

Translation of: C
println("£")
println("\302\243"); # works if your terminal is utf-8

Kotlin[edit]

// version 1.1.2

fun main(args:Array<String>) = println("£")

Lasso[edit]

stdout(' £ ')

Result:

 £ 

Locomotive Basic[edit]

10 PRINT CHR$(163)

Lua[edit]

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[edit]

Print chrcode$(163), "£", chrcode$(127968), "🏠"

Mathematica/Wolfram Language[edit]

FromCharacterCode[{163}]

NetRexx[edit]

/* 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[edit]

echo "£"
echo "札幌"

import unicode
echo Rune(0xa3)

Objeck[edit]

class Program {
  function : Main(args : String[]) ~ Nil {
    "£"->PrintLine();
  }
}

Pascal[edit]

program pound;
uses crt;
begin
  write(chr( 163 ));
end.

Perl[edit]

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[edit]

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[edit]

go =>
  println("£"),
  println(chr(163)),  
  println("太極拳"), % Tàijíquán
  nl.
Output:
£
£
太極拳


PicoLisp[edit]

(prinl (char 26413) (char 24140))  # Sapporo

Output:

札幌

PL/I[edit]

   declare pound character (1) static initial ('9c'x);
   put skip list (pound);

PureBasic[edit]

Print(Chr(163))
£

Python[edit]

Python 2:

print u'\u00a3'
£

Alternatively, as any Unicode character is legal in Python code:

£ = '£'
print(£)
£

R[edit]

cat("£")
Output:
£

Racket[edit]

#lang racket
(display "£")

Raku[edit]

(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[edit]

/*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[edit]

# Project : Terminal control/Display an extended character

see "£"

Output:

£

Ruby[edit]

#encoding: UTF-8  #superfluous in Ruby > 1.9.3
puts "£"

Scala[edit]

Library: Scala
object ExtendedCharacter extends App {
  println("£")
  println("札幌")
}

Seed7[edit]

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[edit]

say '£';
say "\x{FFE1}";
say "\N{FULLWIDTH POUND SIGN}";
say 0xffe1.chr;

Tcl[edit]

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[edit]

module main;
  initial begin
      $display("£");
    end
endmodule


Wren[edit]

System.print("£")

Xidel[edit]

http://videlibri.sourceforge.net/xidel.html

xidel -s -e 'parse-html("&#163; or &#xa3")'
£ or £
echo '"\u00a3"' | xidel -s - -e 'json($raw)'
£

xidel -s -e 'json("""\\u00a3""")' --xquery 'json("&quot;\\u00a3&quot;")'
£
£

XPL0[edit]

code ChOut=8;
ChOut(0, $9C)             \code for IBM PC's extended (OEM) character set


Yabasic[edit]

print chr$(156)


zkl[edit]

If you output device support UTF-8 then:

"\u00a3 \Ua3;".println() //-->£ £