Getting character code

Top Japanese page




Overview

Get Japanese character code automatically.

Flow

  1. Load Jcode
  2. Get the character code

A sample code

 use Jcode;
 
 my $string = "日本語文字列";
 
 my $code = getcode($string);

Description of the code

 use Jcode;

Load Jcode.

 my $string = "日本語文字列";

$string containts Japanese characters. Obtain the code of this Japanese characters.

 my $code = getcode($string);

By getcode method, get the character code from $string automatically. As a return value, the following code is obtained.

 ascii   Ascii (Contains no Japanese Code)
 binary  Binary (Not Text File)
 euc     EUC-JP
 sjis    SHIFT_JIS
 jis     JIS (ISO-2022-JP)
 ucs2    UCS2 (Raw Unicode)
 utf8    UTF8

getcode actually returns two values. One is character code and the other one is the number of matched. It can be done as follows to get two return values.

 my ($code, $match) = getcode($string);