Terminal control/Display an extended character: Difference between revisions
→{{header|BASIC}}: Add AWK. |
→{{header|AWK}}: - Hexadecimal gawkisms removed |
||
Line 24: | Line 24: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
You can print a literal "£". |
You can print a literal "£". |
||
Line 32: | Line 33: | ||
{| class="wikitable" |
{| class="wikitable" |
||
! iso-8859-1 |
! iso-8859-1 |
||
| <tt>"\ |
| <tt>"\243"</tt> |
||
|- |
|- |
||
! euc-jp |
! euc-jp |
||
| <tt>"\ |
| <tt>"\241\362"</tt> |
||
|- |
|- |
||
! utf-8 |
! utf-8 |
||
| <tt>"\ |
| <tt>"\302\243"</tt> |
||
|- |
|- |
||
! gb18030 |
! gb18030 |
||
| <tt>"\ |
| <tt>"\201\60\204\65"</tt> |
||
|} |
|} |
||
<lang awk>BEGIN { print "\ |
<lang awk>BEGIN { print "\302\243" } # if your terminal is utf-8</lang> |
||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
Revision as of 20:44, 22 March 2011
The task is to display an extended (non ascii) character onto the terminal. For this task, we will display a £ (GBP currency sign).
Ada
<lang 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;</lang>
Ada allows Unicode characters in the source, and provides output functions on "wide characters".
<lang ada>with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
procedure Unicode is begin
Put("札幌");
end Unicode;</lang>
AWK
You can print a literal "£".
<lang awk>BEGIN { print "£" }</lang>
You can print a "£" using the escape sequences that match the encoding of your terminal.
iso-8859-1 | "\243" |
---|---|
euc-jp | "\241\362" |
utf-8 | "\302\243" |
gb18030 | "\201\60\204\65" |
<lang awk>BEGIN { print "\302\243" } # if your terminal is utf-8</lang>
BASIC
ZX Spectrum Basic
The ZX Spectrum uses a modified ascii character set that has a uk pound sign at character number 96:
<lang basic>10 PRINT CHR$(96);</lang>
C++
<lang cpp>#include <iostream>
int main() {
std::cout << static_cast<char>(163); // pound sign return 0;
}</lang>
J
<lang J> '£' £
'札幌'
札幌</lang>
Java
<lang 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("札幌"); }
}</lang>
Locomotive Basic
<lang locobasic>10 PRINT CHR$(163)</lang>
PicoLisp
<lang PicoLisp>(prinl (char 26413) (char 24140)) # Sapporo </lang> Output:
札幌
PureBasic
<lang PureBasic>Print(Chr(163))</lang>
£
Python
<lang Python>print u'\u00a3'</lang>
£
Tcl
Provided the system encoding has a “£” symbol in it, this works: <lang tcl>puts \u00a3</lang> 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.