Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #292 Write "Ni Hao" in Chinese to standard output in UTF-8

Write "Hello World and 你好" to standard output in UTF-8.

use utf8;
binmode STDOUT, ':utf8';

print('Hello World and 你好');
  use iso_fortran_env
  integer, parameter :: ucs4  = selected_char_kind ('ISO_10646')
  character(kind=ucs4,  len=30) :: hello_world
  hello_world = ucs4_'Hello World and ' &
                // char (int (z'4F60'), ucs4)     &
                // char (int (z'597D'), ucs4)

  open (output_unit, encoding='UTF-8')
  write (*,*) trim (hello_world)
import "fmt"
fmt.Println("Hello World and 你好")
{$IFDEF WINDOWS}Windows{$ENDIF}
  {$IFDEF WINDOWS}
  SetTextCodePage(Output, CP_UTF8);
  SetConsoleOutputCP(CP_UTF8);
  {$ENDIF}
  writeln('Hello World and 你好');
print('Hello World and \u4f60\u597d')
print('Hello World and 你好')
puts "Hello World and 你好" 
println!("Hello World and 你好")

New implementation...