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 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)

Uniccode characters are entered by their codepoint here. The output unit is set to UTF-8 by the open statement.

New implementation...