Show ASCII table: Difference between revisions
(Added Algol 68 & Algol W) |
(Added C#) |
||
Line 473: | Line 473: | ||
<pre> |
<pre> |
||
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p |
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p |
||
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q |
|||
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r |
|||
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s |
|||
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t |
|||
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u |
|||
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v |
|||
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w |
|||
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x |
|||
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y |
|||
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z |
|||
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { |
|||
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | |
|||
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } |
|||
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ |
|||
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del |
|||
</pre> |
|||
=={{header|C sharp}}== |
|||
<lang csharp>using static System.Console; |
|||
using static System.Linq.Enumerable; |
|||
public class Program |
|||
{ |
|||
static void Main() |
|||
{ |
|||
for (int start = 32; start + 16 * 5 < 128; start++) { |
|||
WriteLine(string.Join("", Range(0, 6).Select(i => $"{start+16*i, 3} : {Text(start+16*i), -6}"))); |
|||
} |
|||
string Text(int index) => index == 32 ? "Sp" : index == 127 ? "Del" : (char)index + ""; |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
32 : Sp 48 : 0 64 : @ 80 : P 96 : ` 112 : p |
|||
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q |
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q |
||
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r |
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r |
||
Line 549: | Line 584: | ||
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del |
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del |
||
</pre> |
</pre> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
Idiomatic Forth version is factored differently than conventional languages, allowing each factor to be tested independently at the console, bottom up. |
Idiomatic Forth version is factored differently than conventional languages, allowing each factor to be tested independently at the console, bottom up. |
Revision as of 13:07, 4 February 2019
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Show ASCII character set from values 32 to 127 in table format.
ALGOL 68
<lang algol68>BEGIN
# generate an ascii table for characters 32 - 127 # INT char count := 1; FOR c FROM 32 TO 127 DO print( ( whole( c, -4 ) , ": " , IF c = 32 THEN "SPC" ELIF c = 127 THEN "DEL" ELSE " " + REPR c + " " FI ) ); IF char count = 0 THEN print( ( newline ) ) FI; ( char count PLUSAB 1 ) MODAB 6 OD
END</lang>
- Output:
32: SPC 33: ! 34: " 35: # 36: $ 37: % 38: & 39: ' 40: ( 41: ) 42: * 43: + 44: , 45: - 46: . 47: / 48: 0 49: 1 50: 2 51: 3 52: 4 53: 5 54: 6 55: 7 56: 8 57: 9 58: : 59: ; 60: < 61: = 62: > 63: ? 64: @ 65: A 66: B 67: C 68: D 69: E 70: F 71: G 72: H 73: I 74: J 75: K 76: L 77: M 78: N 79: O 80: P 81: Q 82: R 83: S 84: T 85: U 86: V 87: W 88: X 89: Y 90: Z 91: [ 92: \ 93: ] 94: ^ 95: _ 96: ` 97: a 98: b 99: c 100: d 101: e 102: f 103: g 104: h 105: i 106: j 107: k 108: l 109: m 110: n 111: o 112: p 113: q 114: r 115: s 116: t 117: u 118: v 119: w 120: x 121: y 122: z 123: { 124: | 125: } 126: ~ 127: DEL
ALGOL W
<lang algolw>begin
% generate an ascii table for chars 32 - 127 % integer cPos; cPos := 0; for i := 32 until 127 do begin if cPos = 0 then write(); cPos := ( cPos + 1 ) rem 6; writeon( i_w := 3, s_w := 0, i, ": " ); if i = 32 then writeon( "Spc ") else if i = 127 then writeon( "Del " ) else writeon( code( i ), " " ) end for_i
end.</lang>
- Output:
32: Spc 33: ! 34: " 35: # 36: $ 37: % 38: & 39: ' 40: ( 41: ) 42: * 43: + 44: , 45: - 46: . 47: / 48: 0 49: 1 50: 2 51: 3 52: 4 53: 5 54: 6 55: 7 56: 8 57: 9 58: : 59: ; 60: < 61: = 62: > 63: ? 64: @ 65: A 66: B 67: C 68: D 69: E 70: F 71: G 72: H 73: I 74: J 75: K 76: L 77: M 78: N 79: O 80: P 81: Q 82: R 83: S 84: T 85: U 86: V 87: W 88: X 89: Y 90: Z 91: [ 92: \ 93: ] 94: ^ 95: _ 96: ` 97: a 98: b 99: c 100: d 101: e 102: f 103: g 104: h 105: i 106: j 107: k 108: l 109: m 110: n 111: o 112: p 113: q 114: r 115: s 116: t 117: u 118: v 119: w 120: x 121: y 122: z 123: { 124: | 125: } 126: ~ 127: Del
AppleScript
<lang applescript>-- asciiTable :: () -> String on asciiTable()
script row on |λ|(ln) script cell on |λ|(x) justifyLeft(12, space, x) end |λ| end script concat(map(cell, ln)) end |λ| end script unlines(map(row, ¬ transpose(chunksOf(16, map(my asciiEntry, ¬ enumFromTo(32, 127))))))
end asciiTable
on run
asciiTable()
end run
-- asciiEntry :: Int -> String on asciiEntry(n)
set k to asciiName(n) if "" ≠ k then justifyRight(4, space, n as string) & " : " & k else k end if
end asciiEntry
-- asciiName :: Int -> String on asciiName(n)
if 32 > n or 127 < n then "" else if 32 = n then "Spc" else if 127 = n then "Del" else chr(n) end if
end asciiName
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- chr :: Int -> Char on chr(n)
character id n
end chr
-- chunksOf :: Int -> [a] -> a on chunksOf(k, xs)
script on go(ys) set ab to splitAt(k, ys) set a to |1| of ab if isNull(a) then {} else {a} & go(|2| of ab) end if end go end script result's go(xs)
end chunksOf
-- comparing :: (a -> b) -> (a -> a -> Ordering) on comparing(f)
script on |λ|(a, b) tell mReturn(f) set fa to |λ|(a) set fb to |λ|(b) if fa < fb then -1 else if fa > fb then 1 else 0 end if end tell end |λ| end script
end comparing
-- concat :: a -> [a] -- concat :: [String] -> String on concat(xs)
set lng to length of xs if 0 < lng and string is class of (item 1 of xs) then set acc to "" else set acc to {} end if repeat with i from 1 to lng set acc to acc & item i of xs end repeat acc
end concat
-- concatMap :: (a -> [b]) -> [a] -> [b] on concatMap(f, xs)
set lng to length of xs if 0 < lng and class of xs is string then set acc to "" else set acc to {} end if tell mReturn(f) repeat with i from 1 to lng set acc to acc & |λ|(item i of xs, i, xs) end repeat end tell return acc
end concatMap
-- enumFromTo :: Int -> Int -> [Int] on enumFromTo(m, n)
if m ≤ n then set lst to {} repeat with i from m to n set end of lst to i end repeat return lst else return {} end if
end enumFromTo
-- foldl :: (a -> b -> a) -> a -> [b] -> a on foldl(f, startValue, xs)
tell mReturn(f) set v to startValue set lng to length of xs repeat with i from 1 to lng set v to |λ|(v, item i of xs, i, xs) end repeat return v end tell
end foldl
-- isNull :: [a] -> Bool -- isNull :: String -> Bool on isNull(xs)
if class of xs is string then "" = xs else {} = xs end if
end isNull
-- justifyLeft :: Int -> Char -> String -> String on justifyLeft(n, cFiller, strText)
if n > length of strText then text 1 thru n of (strText & replicate(n, cFiller)) else strText end if
end justifyLeft
-- justifyRight :: Int -> Char -> String -> String on justifyRight(n, cFiller, strText)
if n > length of strText then text -n thru -1 of ((replicate(n, cFiller) as text) & strText) else strText end if
end justifyRight
-- length :: [a] -> Int on |length|(xs)
length of xs
end |length|
-- max :: Ord a => a -> a -> a on max(x, y)
if x > y then x else y end if
end max
-- maximumBy :: (a -> a -> Ordering) -> [a] -> a on maximumBy(f, xs)
set cmp to mReturn(f) script max on |λ|(a, b) if a is missing value or cmp's |λ|(a, b) < 0 then b else a end if end |λ| end script foldl(max, missing value, xs)
end maximumBy
-- Lift 2nd class handler function into 1st class script wrapper -- mReturn :: First-class m => (a -> b) -> m (a -> b) on mReturn(f)
if class of f is script then f else script property |λ| : f end script end if
end mReturn
-- map :: (a -> b) -> [a] -> [b] on map(f, xs)
tell mReturn(f) set lng to length of xs set lst to {} repeat with i from 1 to lng set end of lst to |λ|(item i of xs, i, xs) end repeat return lst end tell
end map
-- Egyptian multiplication - progressively doubling a list, appending -- stages of doubling to an accumulator where needed for binary -- assembly of a target length -- replicate :: Int -> a -> [a] on replicate(n, a)
set out to {} if n < 1 then return out set dbl to {a} repeat while (n > 1) if (n mod 2) > 0 then set out to out & dbl set n to (n div 2) set dbl to (dbl & dbl) end repeat return out & dbl
end replicate
-- splitAt :: Int -> [a] -> ([a],[a]) on splitAt(n, xs)
if n > 0 and n < length of xs then if class of xs is text then Tuple(items 1 thru n of xs as text, items (n + 1) thru -1 of xs as text) else Tuple(items 1 thru n of xs, items (n + 1) thru -1 of xs) end if else if n < 1 then Tuple({}, xs) else Tuple(xs, {}) end if end if
end splitAt
-- If some of the rows are shorter than the following rows, -- their elements are skipped: -- transpose({{10,11},{20},{},{30,31,32}}) -> {{10, 20, 30}, {11, 31}, {32}} -- transpose :: a -> a on transpose(xxs)
set intMax to |length|(maximumBy(comparing(my |length|), xxs)) set gaps to replicate(intMax, {}) script padded on |λ|(xs) set lng to |length|(xs) if lng < intMax then xs & items (lng + 1) thru -1 of gaps else xs end if end |λ| end script set rows to map(padded, xxs) script cols on |λ|(_, iCol) script cell on |λ|(row) item iCol of row end |λ| end script concatMap(cell, rows) end |λ| end script map(cols, item 1 of rows)
end transpose
-- Tuple (,) :: a -> b -> (a, b) on Tuple(a, b)
{type:"Tuple", |1|:a, |2|:b, length:2}
end Tuple
-- unlines :: [String] -> String on unlines(xs)
set {dlm, my text item delimiters} to ¬ {my text item delimiters, linefeed} set str to xs as text set my text item delimiters to dlm str
end unlines</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
AWK
<lang AWK>
- syntax: GAWK -f SHOW_ASCII_TABLE.AWK
BEGIN {
n00_15 = "NUL,SOH,STX,ETX,EOT,ENQ,ACK,BEL,BS,HT,LF,VT,FF,CR,SO,SI" n16_31 = "DLE,DC1,DC2,DC3,DC4,NAK,SYN,ETB,CAN,EM,SUB,ESC,FS,GS,RS,US" split(n00_15 "," n16_31,arr,",") for (i=0; i<16; i++) { for (j=0+i; j<128; j+=16) { if (j <= 31) { x = arr[j+1] continue # don't show values 0 - 31 } else if (j == 32) { x = "SP" } else if (j == 127) { x = "DEL" } else { x = sprintf("%c",j) } printf("%3d: %-5s",j,x) } printf("\n") } exit(0)
} </lang>
- Output:
32: SP 48: 0 64: @ 80: P 96: ` 112: p 33: ! 49: 1 65: A 81: Q 97: a 113: q 34: " 50: 2 66: B 82: R 98: b 114: r 35: # 51: 3 67: C 83: S 99: c 115: s 36: $ 52: 4 68: D 84: T 100: d 116: t 37: % 53: 5 69: E 85: U 101: e 117: u 38: & 54: 6 70: F 86: V 102: f 118: v 39: ' 55: 7 71: G 87: W 103: g 119: w 40: ( 56: 8 72: H 88: X 104: h 120: x 41: ) 57: 9 73: I 89: Y 105: i 121: y 42: * 58: : 74: J 90: Z 106: j 122: z 43: + 59: ; 75: K 91: [ 107: k 123: { 44: , 60: < 76: L 92: \ 108: l 124: | 45: - 61: = 77: M 93: ] 109: m 125: } 46: . 62: > 78: N 94: ^ 110: n 126: ~ 47: / 63: ? 79: O 95: _ 111: o 127: DEL
C
<lang c>#include <stdio.h>
int main() {
int i, j; char k[4]; for (i = 0; i < 16; ++i) { for (j = 32 + i; j < 128; j += 16) { switch (j) { default: sprintf(k, "%c", j); break; case 32: sprintf(k, "Spc"); break; case 127: sprintf(k, "Del"); break; } printf("%3d : %-3s ", j, k); } printf("\n"); } return 0;
}</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
C#
<lang csharp>using static System.Console; using static System.Linq.Enumerable;
public class Program {
static void Main() { for (int start = 32; start + 16 * 5 < 128; start++) { WriteLine(string.Join("", Range(0, 6).Select(i => $"{start+16*i, 3} : {Text(start+16*i), -6}"))); }
string Text(int index) => index == 32 ? "Sp" : index == 127 ? "Del" : (char)index + ""; }
}</lang>
- Output:
32 : Sp 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Factor
Idiomatic version
<lang factor>USING: combinators formatting io kernel math math.ranges pair-rocket sequences ; IN: rosetta-code.ascii-table
- row-values ( n -- seq ) [ 32 + ] [ 112 + ] bi 16 <range> ;
- ascii>output ( n -- str )
{ 32 => [ "Spc" ] 127 => [ "Del" ] [ "" 1sequence ] } case ;
- print-row ( n -- )
row-values [ dup ascii>output "%3d : %-3s " printf ] each nl ;
- print-ascii-table ( -- ) 16 <iota> [ print-row ] each ;
MAIN: print-ascii-table</lang>
Go translation
<lang factor>USING: combinators formatting io kernel math math.ranges pair-rocket sequences ; IN: rosetta-code.ascii-table
- main ( -- )
16 <iota> [ 32 + 127 16 <range> [ dup { 32 => [ "Spc" ] 127 => [ "Del" ] [ "" 1sequence ] } case "%3d : %-3s " printf ] each nl ] each
MAIN: main</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Forth
Idiomatic Forth version is factored differently than conventional languages, allowing each factor to be tested independently at the console, bottom up. <lang forth>DECIMAL
- ###: ( c -- ) 3 .R ." : " ;
- .CHAR ( c -- )
DUP CASE BL OF ###: ." spc" ENDOF 127 OF ###: ." del" ENDOF DUP ###: EMIT 2 SPACES ENDCASE 3 SPACES ;
- .ROW ( n2 n1 -- )
CR DO I .CHAR 16 +LOOP ;
- ASCII.TABLE ( -- )
16 0 DO 113 I + 32 I + .ROW LOOP ;</lang>
Test Output at the console <lang forth>ASCII.TABLE
32: spc 48: 0 64: @ 80: P 96: ` 112: p 33: ! 49: 1 65: A 81: Q 97: a 113: q 34: " 50: 2 66: B 82: R 98: b 114: r 35: # 51: 3 67: C 83: S 99: c 115: s 36: $ 52: 4 68: D 84: T 100: d 116: t 37: % 53: 5 69: E 85: U 101: e 117: u 38: & 54: 6 70: F 86: V 102: f 118: v 39: ' 55: 7 71: G 87: W 103: g 119: w 40: ( 56: 8 72: H 88: X 104: h 120: x 41: ) 57: 9 73: I 89: Y 105: i 121: y 42: * 58: : 74: J 90: Z 106: j 122: z 43: + 59: ; 75: K 91: [ 107: k 123: { 44: , 60: < 76: L 92: \ 108: l 124: | 45: - 61: = 77: M 93: ] 109: m 125: } 46: . 62: > 78: N 94: ^ 110: n 126: ~ 47: / 63: ? 79: O 95: _ 111: o 127: del ok</lang>
FreePascal
<lang pascal>program ShowASCIITable;
// https://rosettacode.org/wiki/Show_Ascii_table
uses
sysutils, strutils;
var
i, j: Integer; s: String;
begin
i := 0; j := 0; s := ;
for i := 0 to 15 do begin j := 32 + i; while j < 128 do begin case j of 32: s := 'Spc'; 127: s := 'Del'; otherwise s := chr(j); end; write(format('%s : %s', [padLeft(IntToStr(j), 3), padRight(s, 5)])); Inc(j, 16); end; writeln(' '); end;
end.</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Go
<lang go>package main
import "fmt"
func main() {
for i := 0; i < 16; i++ { for j := 32 + i; j < 128; j += 16 { k := string(j) switch j { case 32: k = "Spc" case 127: k = "Del" } fmt.Printf("%3d : %-3s ", j, k) } fmt.Println() }
} </lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Haskell
<lang haskell>import Data.List (intercalate, transpose) import Data.Char (chr)
asciiTable :: String asciiTable =
unlines $ (justifyLeft 12 ' ' =<<) <$> transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127])
main :: IO () main = putStrLn asciiTable
asciiEntry :: Int -> String asciiEntry n =
let k = asciiName n in case k of [] -> k _ -> concat [justifyRight 4 ' ' (show n), " : ", k]
asciiName :: Int -> String asciiName n
| 32 > n = [] | 127 < n = [] | 32 == n = "Spc" | 127 == n = "Del" | otherwise = [chr n]
chunksOf :: Int -> [a] -> a chunksOf k = go
where go t = case splitAt k t of (a, b) | null a -> [] | otherwise -> a : go b
justifyLeft, justifyRight :: Int -> Char -> String -> String justifyLeft n c s = take n (s ++ replicate n c)
justifyRight n c s = drop (length s) (replicate n c ++ s)</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
JavaScript
<lang javascript>(() => {
// asciiTable :: String const asciiTable = () => unlines( map(xs => concat( map(justifyLeft(12, ' '), xs ) ), transpose( chunksOf( 16, map(asciiEntry, enumFromTo(32, 127) ) ) ) ) );
// asciiEntry :: Int -> String const asciiEntry = n => { const k = asciiName(n); return === k ? ( ) : (justifyRight(4, ' ', n.toString()) + ' : ' + k); };
// asciiName :: Int -> String const asciiName = n => 32 > n || 127 < n ? ( ) : 32 === n ? ( 'Spc' ) : 127 === n ? ( 'Del' ) : chr(n);
// GENERIC FUNCTIONS ----------------------------------
// chunksOf :: Int -> [a] -> a const chunksOf = (n, xs) => xs.reduce((a, _, i, xs) => i % n ? a : a.concat([xs.slice(i, i + n)]), []);
// chr :: Int -> Char const chr = String.fromCodePoint;
// comparing :: (a -> b) -> (a -> a -> Ordering) const comparing = f => (x, y) => { const a = f(x), b = f(y); return a < b ? -1 : (a > b ? 1 : 0); };
// concat :: a -> [a] // concat :: [String] -> String const concat = xs => 0 < xs.length ? (() => { const unit = 'string' !== typeof xs[0] ? ( [] ) : ; return unit.concat.apply(unit, xs); })() : [];
// concatMap :: (a -> [b]) -> [a] -> [b] const concatMap = (f, xs) => 0 < xs.length ? (() => { const unit = 'string' !== typeof xs ? ( [] ) : ; return unit.concat.apply(unit, xs.map(f)) })() : [];
// enumFromTo :: Int -> Int -> [Int] const enumFromTo = (m, n) => m <= n ? iterateUntil( x => n <= x, x => 1 + x, m ) : [];
// iterateUntil :: (a -> Bool) -> (a -> a) -> a -> [a] const iterateUntil = (p, f, x) => { const vs = [x]; let h = x; while (!p(h))(h = f(h), vs.push(h)); return vs; };
// justifyLeft :: Int -> Char -> String -> String const justifyLeft = (n, cFiller) => strText => n > strText.length ? ( (strText + cFiller.repeat(n)) .substr(0, n) ) : strText;
// justifyRight :: Int -> Char -> String -> String const justifyRight = (n, cFiller, strText) => n > strText.length ? ( (cFiller.repeat(n) + strText) .slice(-n) ) : strText;
// length :: [a] -> Int const length = xs => xs.length;
// map :: (a -> b) -> [a] -> [b] const map = (f, xs) => xs.map(f);
// maximumBy :: (a -> a -> Ordering) -> [a] -> a const maximumBy = (f, xs) => 0 < xs.length ? ( xs.slice(1) .reduce((a, x) => 0 < f(x, a) ? x : a, xs[0]) ) : undefined;
// replicate :: Int -> a -> [a] const replicate = (n, x) => Array.from({ length: n }, () => x);
// transpose :: a -> a const transpose = tbl => { const gaps = replicate( length(maximumBy(comparing(length), tbl)), [] ), rows = map(xs => xs.concat(gaps.slice(xs.length)), tbl); return map( (_, col) => concatMap(row => [row[col]], rows), rows[0] ); };
// unlines :: [String] -> String const unlines = xs => xs.join('\n');
// MAIN ----------------------------------------------- return asciiTable();
})();</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Julia
The appearance of the table with the extended ASCII characters below depends on the font (code page) used in the terminal and in your browser (DejaVu Sans Mono is a reasonable choice). The output shown is copied from the console ConEmu in Windows 10.
<lang julia>for i in 0:255
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" : i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|" print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c") (i&7)==7 ? println() : print(" ")
end</lang>
- Output:
0 00 NUL 1 01 |☺| 2 02 |☻| 3 03 |♥| 4 04 |♦| 5 05 |♣| 6 06 |♠| 7 07 BEL 8 08 BKS 9 09 TAB 10 0a LF 11 0b |♂| 12 0c |♀| 13 0d CR 14 0e |♫| 15 0f |☼| 16 10 |►| 17 11 |◄| 18 12 |↕| 19 13 |‼| 20 14 |¶| 21 15 |§| 22 16 |■| 23 17 |↨| 24 18 |↑| 25 19 |↓| 26 1a |→| 27 1b ESC 28 1c |∟| 29 1d |↔| 30 1e |▲| 31 1f |▼| 32 20 | | 33 21 |!| 34 22 |"| 35 23 |#| 36 24 |$| 37 25 |%| 38 26 |&| 39 27 |'| 40 28 |(| 41 29 |)| 42 2a |*| 43 2b |+| 44 2c |,| 45 2d |-| 46 2e |.| 47 2f |/| 48 30 |0| 49 31 |1| 50 32 |2| 51 33 |3| 52 34 |4| 53 35 |5| 54 36 |6| 55 37 |7| 56 38 |8| 57 39 |9| 58 3a |:| 59 3b |;| 60 3c |<| 61 3d |=| 62 3e |>| 63 3f |?| 64 40 |@| 65 41 |A| 66 42 |B| 67 43 |C| 68 44 |D| 69 45 |E| 70 46 |F| 71 47 |G| 72 48 |H| 73 49 |I| 74 4a |J| 75 4b |K| 76 4c |L| 77 4d |M| 78 4e |N| 79 4f |O| 80 50 |P| 81 51 |Q| 82 52 |R| 83 53 |S| 84 54 |T| 85 55 |U| 86 56 |V| 87 57 |W| 88 58 |X| 89 59 |Y| 90 5a |Z| 91 5b |[| 92 5c |\| 93 5d |]| 94 5e |^| 95 5f |_| 96 60 |`| 97 61 |a| 98 62 |b| 99 63 |c| 100 64 |d| 101 65 |e| 102 66 |f| 103 67 |g| 104 68 |h| 105 69 |i| 106 6a |j| 107 6b |k| 108 6c |l| 109 6d |m| 110 6e |n| 111 6f |o| 112 70 |p| 113 71 |q| 114 72 |r| 115 73 |s| 116 74 |t| 117 75 |u| 118 76 |v| 119 77 |w| 120 78 |x| 121 79 |y| 122 7a |z| 123 7b |{| 124 7c ||| 125 7d |}| 126 7e |~| 127 7f |?| 128 80 || 129 81 || 130 82 || 131 83 || 132 84 || 133 85 | | 134 86 || 135 87 || 136 88 || 137 89 || 138 8a || 139 8b || 140 8c || 141 8d || 142 8e || 143 8f || 144 90 || 145 91 || 146 92 || 147 93 || 148 94 || 149 95 || 150 96 || 151 97 || 152 98 || 153 99 || 154 9a || 155 9b CSI 156 9c || 157 9d || 158 9e || 159 9f || 160 a0 | | 161 a1 |¡| 162 a2 |¢| 163 a3 |£| 164 a4 |¤| 165 a5 |¥| 166 a6 |¦| 167 a7 |§| 168 a8 |¨| 169 a9 |©| 170 aa |ª| 171 ab |«| 172 ac |¬| 173 ad | | 174 ae |®| 175 af |¯| 176 b0 |°| 177 b1 |±| 178 b2 |²| 179 b3 |³| 180 b4 |´| 181 b5 |µ| 182 b6 |¶| 183 b7 |·| 184 b8 |¸| 185 b9 |¹| 186 ba |º| 187 bb |»| 188 bc |¼| 189 bd |½| 190 be |¾| 191 bf |¿| 192 c0 |À| 193 c1 |Á| 194 c2 |Â| 195 c3 |Ã| 196 c4 |Ä| 197 c5 |Å| 198 c6 |Æ| 199 c7 |Ç| 200 c8 |È| 201 c9 |É| 202 ca |Ê| 203 cb |Ë| 204 cc |Ì| 205 cd |Í| 206 ce |Î| 207 cf |Ï| 208 d0 |Ð| 209 d1 |Ñ| 210 d2 |Ò| 211 d3 |Ó| 212 d4 |Ô| 213 d5 |Õ| 214 d6 |Ö| 215 d7 |×| 216 d8 |Ø| 217 d9 |Ù| 218 da |Ú| 219 db |Û| 220 dc |Ü| 221 dd |Ý| 222 de |Þ| 223 df |ß| 224 e0 |à| 225 e1 |á| 226 e2 |â| 227 e3 |ã| 228 e4 |ä| 229 e5 |å| 230 e6 |æ| 231 e7 |ç| 232 e8 |è| 233 e9 |é| 234 ea |ê| 235 eb |ë| 236 ec |ì| 237 ed |í| 238 ee |î| 239 ef |ï| 240 f0 |ð| 241 f1 |ñ| 242 f2 |ò| 243 f3 |ó| 244 f4 |ô| 245 f5 |õ| 246 f6 |ö| 247 f7 |÷| 248 f8 |ø| 249 f9 |ù| 250 fa |ú| 251 fb |û| 252 fc |ü| 253 fd |ý| 254 fe |þ| 255 ff |ÿ|
This version draws a more fancy table, positioning the items on the console monitor with ANSI control sequences:
<lang julia>print("\e[2J") # clear screen print("""
0 1 2 3 4 5 6 7 8 9 A B C D E F ╔═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╗ ║nul│soh│stx│etx│eot│enq│ack│bel│ bs│tab│ lf│ vt│ ff│ cr│ so│ si║ """) # indent is set by this (least indented) line
for i = 0:14
a = string(i,base=16)
println( "$a ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ $a") println( " ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢") println(i==0 ? " ║dle│dc1│dc2│dc3│dc4│nak│syn│etb│can│ em│eof│esc│ fs│ gs│ rs│ us║"
: " ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║")
end println("""
f ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ f ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝ 0 1 2 3 4 5 6 7 8 9 A B C D E F """) # """ string is indented here
for i = 1:255
r,c = divrem(i,16) r,c = 3r+4,4c+5 i > 31 && print("\e[$(r-1);$(c-1)H$(lpad(i,3))") 6<i<11 || i==155 || i==173 || print("\e[$r;$(c)H$(Char(i))")
end print("\e[54;1H")</lang>
- Output:
0 1 2 3 4 5 6 7 8 9 A B C D E F ╔═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╗ ║nul│soh│stx│etx│eot│enq│ack│bel│ bs│tab│ lf│ vt│ ff│ cr│ so│ si║ 0 ║ │ ☺ │ ☻ │ ♥ │ ♦ │ ♣ │ ♠ │ │ │ │ │ ♂ │ ♀ │ │ ♫ │ ☼ ║ 0 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║dle│dc1│dc2│dc3│dc4│nak│syn│etb│can│ em│eof│esc│ fs│ gs│ rs│ us║ 1 ║ ► │ ◄ │ ↕ │ ‼ │ ¶ │ § │ ■ │ ↨ │ ↑ │ ↓ │ → │ │ ∟ │ ↔ │ ▲ │ ▼ ║ 1 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 32│ 33│ 34│ 35│ 36│ 37│ 38│ 39│ 40│ 41│ 42│ 43│ 44│ 45│ 46│ 47║ 2 ║ │ ! │ " │ # │ $ │ % │ & │ ' │ ( │ ) │ * │ + │ , │ - │ . │ / ║ 2 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 48│ 49│ 50│ 51│ 52│ 53│ 54│ 55│ 56│ 57│ 58│ 59│ 60│ 61│ 62│ 63║ 3 ║ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ : │ ; │ < │ = │ > │ ? ║ 3 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 64│ 65│ 66│ 67│ 68│ 69│ 70│ 71│ 72│ 73│ 74│ 75│ 76│ 77│ 78│ 79║ 4 ║ @ │ A │ B │ C │ D │ E │ F │ G │ H │ I │ J │ K │ L │ M │ N │ O ║ 4 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 80│ 81│ 82│ 83│ 84│ 85│ 86│ 87│ 88│ 89│ 90│ 91│ 92│ 93│ 94│ 95║ 5 ║ P │ Q │ R │ S │ T │ U │ V │ W │ X │ Y │ Z │ [ │ \ │ ] │ ^ │ _ ║ 5 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 96│ 97│ 98│ 99│100│101│102│103│104│105│106│107│108│109│110│111║ 6 ║ ` │ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ m │ n │ o ║ 6 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║112│113│114│115│116│117│118│119│120│121│122│123│124│125│126│127║ 7 ║ p │ q │ r │ s │ t │ u │ v │ w │ x │ y │ z │ { │ | │ } │ ~ │ ? ║ 7 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║128│129│130│131│132│133│134│135│136│137│138│139│140│141│142│143║ 8 ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ 8 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║144│145│146│147│148│149│150│151│152│153│154│155│156│157│158│159║ 9 ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ 9 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║160│161│162│163│164│165│166│167│168│169│170│171│172│173│174│175║ a ║ │ ¡ │ ¢ │ £ │ ¤ │ ¥ │ ¦ │ § │ ¨ │ © │ ª │ « │ ¬ │ │ ® │ ¯ ║ a ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║176│177│178│179│180│181│182│183│184│185│186│187│188│189│190│191║ b ║ ° │ ± │ ² │ ³ │ ´ │ µ │ ¶ │ · │ ¸ │ ¹ │ º │ » │ ¼ │ ½ │ ¾ │ ¿ ║ b ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║192│193│194│195│196│197│198│199│200│201│202│203│204│205│206│207║ c ║ À │ Á │ Â │ Ã │ Ä │ Å │ Æ │ Ç │ È │ É │ Ê │ Ë │ Ì │ Í │ Î │ Ï ║ c ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║208│209│210│211│212│213│214│215│216│217│218│219│220│221│222│223║ d ║ Ð │ Ñ │ Ò │ Ó │ Ô │ Õ │ Ö │ × │ Ø │ Ù │ Ú │ Û │ Ü │ Ý │ Þ │ ß ║ d ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║224│225│226│227│228│229│230│231│232│233│234│235│236│237│238│239║ e ║ à │ á │ â │ ã │ ä │ å │ æ │ ç │ è │ é │ ê │ ë │ ì │ í │ î │ ï ║ e ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║240│241│242│243│244│245│246│247│248│249│250│251│252│253│254│255║ f ║ ð │ ñ │ ò │ ó │ ô │ õ │ ö │ ÷ │ ø │ ù │ ú │ û │ ü │ ý │ þ │ ÿ ║ f ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝ 0 1 2 3 4 5 6 7 8 9 A B C D E F
A similar output can be produced without ANSI control sequences, just filling up a huge string and printing it. Below is a general Object (struct) and the corresponding methods to draw a table of arbitrary shape in the console. It is the Julia way of OOP. The Table structure holds the relevant data and the constructor. The Base.iterate function extends the general iterate function, and allows using the field names in a function, w/o prefixing them with "<structName>." The function prt() fills up a string with data, formatting spaces and new-lines, and prints it to the console. <lang julia>#= CONSOLE TABLES =============================================================
rn: nrows, rh: height of rows cn: ncols, cw: width of columns T[rn,cn,rh] table data strings cr: rows in colum headers CH[cn,cr] column header strings of max cw length hl: lengths of row header strings RH[rn,rh] row header strings of max length hl
==============================================================================#
struct Table
rn::Int; rh::Int; cn::Int; cw::Int; T::Array{String,3} cr::Int; CH::Array{String,2} hl::Int; RH::Array{String,2} function Table(rn,rh,cn,cw,cr,hl) # constructor new(rn,rh,cn,cw,fill("",(rn,cn,rh)), # arrays initialized with empty strings cr,fill("",(cr,cn)), hl,fill("",(rn,rh))) end
end Base.iterate(T::Table,i=1) = i<=nfields(T) ? (getfield(T,i),i+1) : nothing
cpad(s::String,n::Integer) = (m=length(s))<n ? lpad(rpad(s,(n+m)>>1),n) : first(s,n)
function prt((rn,rh,cn,cw,T, cr,CH, hl,RH)::Table)
TL,TX,TR,BH = '╔','╤','╗','═' IL,IX,IR,IV,IH='╟','┼','╢','│','─' BL,BX,BR,BV = '╚','╧','╝','║'
u,v,w,d,t = BH^cw, IH^cw, " "^hl, cn-2, " "^hl b = w*(cn==1 ? IL*v*IR : IL*v*(IX*v)^d*IX*v*IR)*'\n' # internal separator for r = 1:cr for c = 1:cn t*=cpad(CH[r,c],cw+1) end t *= "\n$w" end t *= (cn==1 ? TL*u*TR : TL*u*(TX*u)^d*TX*u*TR)*'\n' # top border for r = 1:rn for p = 1:rh s = cpad(RH[r,p],hl)*BV for c = 1:cn-1 s *= cpad(T[r,c,p],cw) * IV end t*= s * cpad(T[r,cn,p],cw) * BV *'\n' end t*=r<rn ? b : cn<2 ? w*BL*u*BR : w*BL*u*(BX*u)^d*BX*u*BR # bottom border end println("\n$t\n")
end</lang> Using these is simple, only provide the data, and prt it. <lang julia>Tbl = Table(16,2,16,3, 2,3) # construct table Tbl.CH[1,:] = string.(0:15,base=16) # Column headers Tbl.RH[:,2] = string.(0:15,base=16) # Row headers for i = 0:255 # populate table, exclude special characters
Tbl.T[i>>4+1,i&15+1,1:2]=["$i",i∈(0,7,8,9,10,13,27,155) ? "" : "$(Char(i))"]
end prt(Tbl) # format and print table on console</lang>
Kotlin
<lang scala>// Version 1.2.60
fun main(args: Array<String>) {
for (i in 0..15) { for (j in 32 + i..127 step 16) { val k = when (j) { 32 -> "Spc" 127 -> "Del" else -> j.toChar().toString() } System.out.printf("%3d : %-3s ", j, k) } println() }
}</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Perl
Output in the same style as Perl 6.
<lang perl>use charnames ':full'; binmode STDOUT, ':utf8';
sub glyph {
my($n) = @_; if ($n < 33) { chr 0x2400 + $n } # display symbol names for invisible glyphs elsif ($n==124) { '|' } elsif ($n==127) { 'DEL' } else { chr $n }
}
print qq[{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"\n];
for (0..127) {
print qq[|-\n] unless $_ % 16;; printf qq[|%d
0x%02X
%s\n], $_, $_, charnames::viacode($_), glyph($_); }
} print qq[|}\n];</lang>
Perl 6
Alternately, and perhaps more usefully, output as a wiki-table rather than ASCII art. Hover mouse over the glyph to get the name.
<lang perl6>sub glyph ($_) {
when * < 33 { (0x2400 + $_).chr } # display symbol names for invisible glyphs when 127 { '␡' } default { .chr }
}
say '{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"';
for (^128).rotor(16) -> @row {
say '|-'; printf(q[|%d
0x%02X
%s] ~ "\n", $_, $_, .&glyph.uniname.subst('SYMBOL FOR ', ), .&glyph.subst('|', '|')) for @row;
}
say '|}';</lang>
- Output:
0 0x00 ␀ |
1 0x01 ␁ |
2 0x02 ␂ |
3 0x03 ␃ |
4 0x04 ␄ |
5 0x05 ␅ |
6 0x06 ␆ |
7 0x07 ␇ |
8 0x08 ␈ |
9 0x09 ␉ |
10 0x0A ␊ |
11 0x0B ␋ |
12 0x0C ␌ |
13 0x0D ␍ |
14 0x0E ␎ |
15 0x0F ␏ |
16 0x10 ␐ |
17 0x11 ␑ |
18 0x12 ␒ |
19 0x13 ␓ |
20 0x14 ␔ |
21 0x15 ␕ |
22 0x16 ␖ |
23 0x17 ␗ |
24 0x18 ␘ |
25 0x19 ␙ |
26 0x1A ␚ |
27 0x1B ␛ |
28 0x1C ␜ |
29 0x1D ␝ |
30 0x1E ␞ |
31 0x1F ␟ |
32 0x20 ␠ |
33 0x21 ! |
34 0x22 " |
35 0x23 # |
36 0x24 $ |
37 0x25 % |
38 0x26 & |
39 0x27 ' |
40 0x28 ( |
41 0x29 ) |
42 0x2A * |
43 0x2B + |
44 0x2C , |
45 0x2D - |
46 0x2E . |
47 0x2F / |
48 0x30 0 |
49 0x31 1 |
50 0x32 2 |
51 0x33 3 |
52 0x34 4 |
53 0x35 5 |
54 0x36 6 |
55 0x37 7 |
56 0x38 8 |
57 0x39 9 |
58 0x3A : |
59 0x3B ; |
60 0x3C < |
61 0x3D = |
62 0x3E > |
63 0x3F ? |
64 0x40 @ |
65 0x41 A |
66 0x42 B |
67 0x43 C |
68 0x44 D |
69 0x45 E |
70 0x46 F |
71 0x47 G |
72 0x48 H |
73 0x49 I |
74 0x4A J |
75 0x4B K |
76 0x4C L |
77 0x4D M |
78 0x4E N |
79 0x4F O |
80 0x50 P |
81 0x51 Q |
82 0x52 R |
83 0x53 S |
84 0x54 T |
85 0x55 U |
86 0x56 V |
87 0x57 W |
88 0x58 X |
89 0x59 Y |
90 0x5A Z |
91 0x5B [ |
92 0x5C \ |
93 0x5D ] |
94 0x5E ^ |
95 0x5F _ |
96 0x60 ` |
97 0x61 a |
98 0x62 b |
99 0x63 c |
100 0x64 d |
101 0x65 e |
102 0x66 f |
103 0x67 g |
104 0x68 h |
105 0x69 i |
106 0x6A j |
107 0x6B k |
108 0x6C l |
109 0x6D m |
110 0x6E n |
111 0x6F o |
112 0x70 p |
113 0x71 q |
114 0x72 r |
115 0x73 s |
116 0x74 t |
117 0x75 u |
118 0x76 v |
119 0x77 w |
120 0x78 x |
121 0x79 y |
122 0x7A z |
123 0x7B { |
124 0x7C | |
125 0x7D } |
126 0x7E ~ |
127 0x7F ␡ |
Phix
<lang Phix>sequence ascii = {} for ch=32 to 127 do
ascii = append(ascii,sprintf("%4d (#%02x): %c ",ch))
end for puts(1,substitute(join_by(ascii,16,6),x"7F","del"))</lang>
- Output:
32 (#20): 48 (#30): 0 64 (#40): @ 80 (#50): P 96 (#60): ` 112 (#70): p 33 (#21): ! 49 (#31): 1 65 (#41): A 81 (#51): Q 97 (#61): a 113 (#71): q 34 (#22): " 50 (#32): 2 66 (#42): B 82 (#52): R 98 (#62): b 114 (#72): r 35 (#23): # 51 (#33): 3 67 (#43): C 83 (#53): S 99 (#63): c 115 (#73): s 36 (#24): $ 52 (#34): 4 68 (#44): D 84 (#54): T 100 (#64): d 116 (#74): t 37 (#25): % 53 (#35): 5 69 (#45): E 85 (#55): U 101 (#65): e 117 (#75): u 38 (#26): & 54 (#36): 6 70 (#46): F 86 (#56): V 102 (#66): f 118 (#76): v 39 (#27): ' 55 (#37): 7 71 (#47): G 87 (#57): W 103 (#67): g 119 (#77): w 40 (#28): ( 56 (#38): 8 72 (#48): H 88 (#58): X 104 (#68): h 120 (#78): x 41 (#29): ) 57 (#39): 9 73 (#49): I 89 (#59): Y 105 (#69): i 121 (#79): y 42 (#2A): * 58 (#3A): : 74 (#4A): J 90 (#5A): Z 106 (#6A): j 122 (#7A): z 43 (#2B): + 59 (#3B): ; 75 (#4B): K 91 (#5B): [ 107 (#6B): k 123 (#7B): { 44 (#2C): , 60 (#3C): < 76 (#4C): L 92 (#5C): \ 108 (#6C): l 124 (#7C): | 45 (#2D): - 61 (#3D): = 77 (#4D): M 93 (#5D): ] 109 (#6D): m 125 (#7D): } 46 (#2E): . 62 (#3E): > 78 (#4E): N 94 (#5E): ^ 110 (#6E): n 126 (#7E): ~ 47 (#2F): / 63 (#3F): ? 79 (#4F): O 95 (#5F): _ 111 (#6F): o 127 (#7F): del
Python
HTML
After Perl6, but creating an HTML table: <lang python>from unicodedata import name from html import escape
def pp(n):
if n <= 32: return chr(0x2400 + n) if n == 127: return '␡' return chr(n)
print('
\n ') for n in range(128): if n %16 == 0 and 1 < n: print(" ") print(f' ') print(""" \n{n} 0x{n:02x} {escape(pp(n))} |
""")</lang>
- Output:
0 0x00 ␀ |
1 0x01 ␁ |
2 0x02 ␂ |
3 0x03 ␃ |
4 0x04 ␄ |
5 0x05 ␅ |
6 0x06 ␆ |
7 0x07 ␇ |
8 0x08 ␈ |
9 0x09 ␉ |
10 0x0a ␊ |
11 0x0b ␋ |
12 0x0c ␌ |
13 0x0d ␍ |
14 0x0e ␎ |
15 0x0f ␏ |
16 0x10 ␐ |
17 0x11 ␑ |
18 0x12 ␒ |
19 0x13 ␓ |
20 0x14 ␔ |
21 0x15 ␕ |
22 0x16 ␖ |
23 0x17 ␗ |
24 0x18 ␘ |
25 0x19 ␙ |
26 0x1a ␚ |
27 0x1b ␛ |
28 0x1c ␜ |
29 0x1d ␝ |
30 0x1e ␞ |
31 0x1f ␟ |
32 0x20 ␠ |
33 0x21 ! |
34 0x22 " |
35 0x23 # |
36 0x24 $ |
37 0x25 % |
38 0x26 & |
39 0x27 ' |
40 0x28 ( |
41 0x29 ) |
42 0x2a * |
43 0x2b + |
44 0x2c , |
45 0x2d - |
46 0x2e . |
47 0x2f / |
48 0x30 0 |
49 0x31 1 |
50 0x32 2 |
51 0x33 3 |
52 0x34 4 |
53 0x35 5 |
54 0x36 6 |
55 0x37 7 |
56 0x38 8 |
57 0x39 9 |
58 0x3a : |
59 0x3b ; |
60 0x3c < |
61 0x3d = |
62 0x3e > |
63 0x3f ? |
64 0x40 @ |
65 0x41 A |
66 0x42 B |
67 0x43 C |
68 0x44 D |
69 0x45 E |
70 0x46 F |
71 0x47 G |
72 0x48 H |
73 0x49 I |
74 0x4a J |
75 0x4b K |
76 0x4c L |
77 0x4d M |
78 0x4e N |
79 0x4f O |
80 0x50 P |
81 0x51 Q |
82 0x52 R |
83 0x53 S |
84 0x54 T |
85 0x55 U |
86 0x56 V |
87 0x57 W |
88 0x58 X |
89 0x59 Y |
90 0x5a Z |
91 0x5b [ |
92 0x5c \ |
93 0x5d ] |
94 0x5e ^ |
95 0x5f _ |
96 0x60 ` |
97 0x61 a |
98 0x62 b |
99 0x63 c |
100 0x64 d |
101 0x65 e |
102 0x66 f |
103 0x67 g |
104 0x68 h |
105 0x69 i |
106 0x6a j |
107 0x6b k |
108 0x6c l |
109 0x6d m |
110 0x6e n |
111 0x6f o |
112 0x70 p |
113 0x71 q |
114 0x72 r |
115 0x73 s |
116 0x74 t |
117 0x75 u |
118 0x76 v |
119 0x77 w |
120 0x78 x |
121 0x79 y |
122 0x7a z |
123 0x7b { |
124 0x7c | |
125 0x7d } |
126 0x7e ~ |
127 0x7f ␡ |
Plain text
Composed from generic abstractions: <lang python>from itertools import (chain)
- main :: IO ()
def main():
print( asciiTable() )
- asciiTable :: String
def asciiTable():
return unlines( _map(compose(concat)(_map(justifyLeft(12)(' '))))( transpose( chunksOf(16)( _map(asciiEntry)( enumFromTo(32)(127) ) ) ) ) )
- asciiEntry :: Int -> String
def asciiEntry(n):
k = asciiName(n) return k if == k else ( concat([justifyRight(3)(' ')(str(n)), ' : ', k]) )
- asciiName :: Int -> String
def asciiName(n):
return if 32 > n or 127 < n else ( 'Spc' if 32 == n else ( 'Del' if 127 == n else chr(n) ) )
- GENERIC ABSTRACTIONS ------------------------------------
- chunksOf :: Int -> [a] -> a
def chunksOf(n):
def go(t): (a, b) = splitAt(n)(t) return [] if 0 == len(a) else ( [a] + go(b) ) return lambda xs: go(xs)
- compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
def compose(g):
return lambda f: lambda x: g(f(x))
- concat :: a -> [a]
- concat :: [String] -> String
def concat(xxs):
xs = list(chain.from_iterable(xxs)) return [] if not xs else ( .join(xs) if type(xs[0]) is str else xs )
- enumFromTo :: Int -> Int -> [Int]
def enumFromTo(m):
return lambda n: list(range(m, 1 + n))
- justifyLeft :: Int -> Char -> String -> String
def justifyLeft(n):
return lambda cFiller: lambda a: ( (str(a) + (n * cFiller))[:n] )
- justifyRight :: Int -> Char -> String -> String
def justifyRight(n):
return lambda cFiller: lambda a: ( ((n * cFiller) + str(a))[-n:] )
- Curried map, returning a list
- map :: (a -> b) -> [a] -> [b]
def _map(f):
return lambda xs: list(map(f, xs))
- splitAt :: Int -> [a] -> ([a], [a])
def splitAt(n):
return lambda xs: (xs[0:n], xs[n:])
def transpose(xs):
return list(map(list, zip(*xs)))
- unlines :: [String] -> String
def unlines(xs):
return '\n'.join(xs)
- MAIN ---
main()</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
REXX
Note that some REXX interpreters can't display
the '1b'x (esc) character glyph properly, so a special check was
made for those two REXXes to not show that glyph.
A fair amount of code was added to show all possible characters (glyphs), with special attention paid to:
- presenting an index (top and bottom; left and right).
- using a grid instead of using blanks for visual fidelity.
- using a two─tired type of grid (with single─ and double─lined cells).
- preserving indentation and other whitespace.
- showing the function of some characters (those that have a lower value than a blank).
- showing the name of a blank (as bla).
- the suppression of displaying particular glyphs by REXX that are preempted by the OS.
- adding homage to the adage of: anything worth doing is worth doing well.
<lang rexx>/*REXX program displays an ASCII table of characters (within a 16x16 indexed grid).*/ parse upper version !ver . /*some REXXes can't display '1b'x glyph*/ !pcRexx= 'REXX/PERSONAL'==!ver | 'REXX/PC'==!ver /*is this PC/REXX or REXX/Personal? */
func= ' nul soh stx etx eot enq ack bel bs tab lf vt ff cr so si ' || , " dle dc1 dc2 dc3 dc4 nak syn etb can em eof esc fs gs rs us "
hdr= left(, 7) /*prepend blanks to HDR (indentation).*/ call xhdr /*construct a top index for the grid.*/ call grid '╔', "╤", '╗', "═══" /*construct & display bottom of a cell.*/ iidx= left(, length(hdr) - 4) /*the length of the indentation of idx.*/ cant= copies('═', 3) /*can't show a character with this REXX*/
/* [↓] construct a sixteen-row grid. */ do j=0 by 16 for 16; idx= left(d2x(j),1,2) /*prepend an index literal for the grid*/ _= iidx idx ' '; _h= iidx " " /*an index and indent; without an index*/ sep= '║' /*assign a character to cell separator.*/ do #=j to j+15; chr= center( d2c(#), 3) /*true char glyph.*/ if #>6 & #<11 | #==13 then chr= cant /*can't show these glyphs.*/ /*esc*/ if #==27 then if !pcRexx then chr= cant /* " " this glyph. */ else chr= center( '1b'x, 3) /*true char glyph.*/ if # <32 then _h= _h || sep || right(word(func, #+1), 3) /*show a function.*/ if #==32 then chr= 'bla' /*spell out (within 3 chars) a "blank".*/ if # >31 then _h= /*Above a blank? Then nullify 3rd line*/ _= _ || sep || chr; sep= '│' /*append grid cell; use a new sep char.*/ end /*#*/ if _h\== then say _h'║ ' /*append the last grid cell character.*/ say _'║ ' idx /*append an index to the grid line.*/ if j\==240 then call grid '╟',"┼",'╢','───' /*construct & display most cell bottoms*/ end /*j*/
call grid '╚', "╧", '╝', "═══" /*construct & display last cell bottom.*/ call xhdr /*construct a bottom index for the grid*/ exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ xhdr: say; _=hdr; sep=' '; do k=0 for 16; _=_' ' d2x(k)" "; end; say _; say; return grid: arg $1,$2,$3,$4;_=hdr; do 16; _=_ || $1 || $4; $1= $2; end; say _ || $3; return</lang>
- output showing a horizontal formatted grid (table):
(Code page 437 was used for the example below using DOS under Microsoft Windows.)
0 1 2 3 4 5 6 7 8 9 A B C D E F ╔═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╗ ║nul│soh│stx│etx│eot│enq│ack│bel│ bs│tab│ lf│ vt│ ff│ cr│ so│ si║ 0 ║ │ ☺ │ ☻ │ ♥ │ ♦ │ ♣ │ ♠ │═══│═══│═══│═══│ ♂ │ ♀ │═══│ ♫ │ ☼ ║ 0 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║dle│dc1│dc2│dc3│dc4│nak│syn│etb│can│ em│eof│esc│ fs│ gs│ rs│ us║ 1 ║ ► │ ◄ │ ↕ │ ‼ │ ¶ │ § │ ▬ │ ↨ │ ↑ │ ↓ │ → │ ← │ ∟ │ ↔ │ ▲ │ ▼ ║ 1 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 2 ║bla│ ! │ " │ # │ $ │ % │ & │ ' │ ( │ ) │ * │ + │ , │ - │ . │ / ║ 2 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 3 ║ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ : │ ; │ < │ = │ > │ ? ║ 3 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 4 ║ @ │ A │ B │ C │ D │ E │ F │ G │ H │ I │ J │ K │ L │ M │ N │ O ║ 4 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 5 ║ P │ Q │ R │ S │ T │ U │ V │ W │ X │ Y │ Z │ [ │ \ │ ] │ ^ │ _ ║ 5 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 6 ║ ` │ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ m │ n │ o ║ 6 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 7 ║ p │ q │ r │ s │ t │ u │ v │ w │ x │ y │ z │ { │ | │ } │ ~ │ ⌂ ║ 7 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 8 ║ Ç │ ü │ é │ â │ ä │ à │ å │ ç │ ê │ ë │ è │ ï │ î │ ì │ Ä │ Å ║ 8 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 9 ║ É │ æ │ Æ │ ô │ ö │ ò │ û │ ù │ ÿ │ Ö │ Ü │ ¢ │ £ │ ¥ │ ₧ │ ƒ ║ 9 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ A ║ á │ í │ ó │ ú │ ñ │ Ñ │ ª │ º │ ¿ │ ⌐ │ ¬ │ ½ │ ¼ │ ¡ │ « │ » ║ A ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ B ║ ░ │ ▒ │ ▓ │ │ │ ┤ │ ╡ │ ╢ │ ╖ │ ╕ │ ╣ │ ║ │ ╗ │ ╝ │ ╜ │ ╛ │ ┐ ║ B ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ C ║ └ │ ┴ │ ┬ │ ├ │ ─ │ ┼ │ ╞ │ ╟ │ ╚ │ ╔ │ ╩ │ ╦ │ ╠ │ ═ │ ╬ │ ╧ ║ C ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ D ║ ╨ │ ╤ │ ╥ │ ╙ │ ╘ │ ╒ │ ╓ │ ╫ │ ╪ │ ┘ │ ┌ │ █ │ ▄ │ ▌ │ ▐ │ ▀ ║ D ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ E ║ α │ ß │ Γ │ π │ Σ │ σ │ µ │ τ │ Φ │ Θ │ Ω │ δ │ ∞ │ φ │ ε │ ∩ ║ E ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ F ║ ≡ │ ± │ ≥ │ ≤ │ ⌠ │ ⌡ │ ÷ │ ≈ │ ° │ ∙ │ · │ √ │ ⁿ │ ² │ ■ │ ║ F ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝ 0 1 2 3 4 5 6 7 8 9 A B C D E F
VBA
<lang VB> Public Sub ascii()
Dim s As String For i = 0 To 16 For j = 32 + i To 127 Step 16 Select Case j Case 32: s = "Spc" Case 127: s = "Del" Case Else: s = Chr(j) End Select Debug.Print Tab(10 * (j - 32 - i) / 16); Spc(3 - Len(CStr(j))); j & ": " & s; Next j Debug.Print vbCrLf Next i
End Sub </lang>
- Output:
32: Spc 48: 0 64: @ 80: P 96: ` 112: p 33: ! 49: 1 65: A 81: Q 97: a 113: q 34: " 50: 2 66: B 82: R 98: b 114: r 35: # 51: 3 67: C 83: S 99: c 115: s 36: $ 52: 4 68: D 84: T 100: d 116: t 37: % 53: 5 69: E 85: U 101: e 117: u 38: & 54: 6 70: F 86: V 102: f 118: v 39: ' 55: 7 71: G 87: W 103: g 119: w 40: ( 56: 8 72: H 88: X 104: h 120: x 41: ) 57: 9 73: I 89: Y 105: i 121: y 42: * 58: : 74: J 90: Z 106: j 122: z 43: + 59: ; 75: K 91: [ 107: k 123: { 44: , 60: < 76: L 92: \ 108: l 124: | 45: - 61: = 77: M 93: ] 109: m 125: } 46: . 62: > 78: N 94: ^ 110: n 126: ~ 47: / 63: ? 79: O 95: _ 111: o 127: Del 48: 0 64: @ 80: P 96: ` 112: p
Ring
<lang ring>
- Project : Show Ascii table
load "guilib.ring" load "stdlib.ring"
decarr = newlist(16,6) ascarr = newlist(16,6)
new qapp
{ win1 = new qwidget() { setwindowtitle("Show Ascii table") setgeometry(100,100,800,600) for n = 1 to 16 for m = 1 to 6 decarr[n][m] = new qpushbutton(win1) { x = 150+m*60 y = 30 + n*30 ind = string((m-1)*16+n+31) setgeometry(x,y,30,30) settext(ind) } next next for n = 1 to 16 for m = 1 to 6 ascarr[n][m] = new qpushbutton(win1) { x = 180+m*60 y = 30 + n*30 ind = (m-1)*16+n+31 setgeometry(x,y,30,30) if ind = 32 settext("Spc") loop ok if ind = 127 settext("Del") loop ok settext(char(ind)) } next next show() } exec() }
</lang> Output:
Rust
<lang Rust>fn main() {
for i in 0u8..16 { for j in ((32+i)..128).step_by(16) { let k = (j as char).to_string(); print!("{:3} : {:<3} ", j, match j { 32 => "Spc", 127 => "Del", _ => &k, }); } println!(); }
}</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
zkl
<lang zkl>const width=9; println(" ",[0..width].pump(String,"%4d".fmt)); [30..127].pump("".println,T(Void.Read,width,False), // don't fail on short lines
fcn(a,b,c){ String("%3d: ".fmt(a), vm.arglist.pump(String,"toChar", // parameters (ints) to list to text T("replace","\x1e",""),T("replace","\x1f",""), // 30,31 T("replace"," ","spc"),T("replace","\x7f","del"), "%-4s".fmt) ) })</lang>
- Output:
0 1 2 3 4 5 6 7 8 9 30: spc ! " # $ % & ' 40: ( ) * + , - . / 0 1 50: 2 3 4 5 6 7 8 9 : ; 60: < = > ? @ A B C D E 70: F G H I J K L M N O 80: P Q R S T U V W X Y 90: Z [ \ ] ^ _ ` a b c 100: d e f g h i j k l m 110: n o p q r s t u v w 120: x y z { | } ~ del