perl

文字変換、文字列変換

EUC-JPS-JISUTF8UTF16JIS文字実体参照HEXVAL
A1A18140E3808030002121  300012288
A1A28141E3808130012122、300112289
A1A38142E3808230022123。300212290
A1A48143EFBC8CFF0C2124,ff0c65292
A1A58144EFBC8EFF0E2125.ff0e65294
A1A78146EFBC9AFF1A2127:ff1a65306
A1A88147EFBC9BFF1B2128;ff1b65307
A1A98148EFBC9FFF1F2129?ff1f65311
A1AA8149EFBC81FF01212A!ff0165281
A1AB814AE3829B309B212B゛309b12443
A1AC814BE3829C309C212C゜309c12444
A1AD814CC2B4B4212D´´00b4180
A1AE814DEFBD80FF40212E`ff4065344
A1AF814EC2A8A8212F¨¨00a8168
A1B0814FEFBCBEFF3E2130^ff3e65342
A1B18150EFBFA3FFE32131 ̄ffe365507
A1B28151EFBCBFFF3F2132__ff3f65343
A1B38152E383BD30FD2133ヽ30fd12541
A1B48153E383BE30FE2134ヾ30fe12542
A1B58154E3829D309D2135ゝ309d12445
A1B68155E3829E309E2136ゞ309e12446
A1B78156E3808330032137〃300312291
A1B88157E4BB9D4EDD2138仝4edd20189
A1B98158E3808530052139々300512293
A1BA8159E380863006213A〆300612294
A1BB815AE380873007213B〇300712295
A1BC815BE383BC30FC213Cー30fc12540
A1BD815CE280952015213D―20158213
A1BE815DE280902010213E‐20108208
A1BF815EEFBC8FFF0F213F/ff0f65295
A1C0815FEFBCBCFF3C2140\ff3c65340
A1C18160EFBD9EFF5E2141~ff5e65374
A1C28161E288A522252142∥22258741
A1C38162EFBD9CFF5C2143|ff5c65372
A1C48163E280A620262144…20268230
A1C58164E280A520252145‥20258229
A1C68165E2809820182146‘20188216
A1C78166E2809920192147’20198217
A1C88167E2809C201C2148“201c8220
A1C98168E2809D201D2149”201d8221
A1CA8169EFBC88FF08214A(ff0865288
A1CB816AEFBC89FF09214B)ff0965289
A1CC816BE380943014214C〔301412308
A1CD816CE380953015214D〕301512309
A1CE816DEFBCBBFF3B214E[ff3b65339
A1CF816EEFBCBDFF3D214F]ff3d65341
A1D0816FEFBD9BFF5B2150{ff5b65371
A1D18170EFBD9DFF5D2151}ff5d65373
A1D28171E3808830082152〈300812296
A1D38172E3808930092153〉300912297
A1D48173E3808A300A2154《300a12298
A1D58174E3808B300B2155》300b12299
A1D68175E3808C300C2156「300c12300
A1D78176E3808D300D2157」300d12301
A1D88177E3808E300E2158『300e12302
A1D98178E3808F300F2159』300f12303
A1DA8179E380903010215A【301012304
A1DB817AE380913011215B】301112305
A1DC817BEFBC8BFF0B215C+ff0b65291
A1DD817CEFBC8DFF0D215D-ff0d65293
A1DE817DC2B1B1215E±±00b1177
A1DF817EC397D7215F××00d7215
A1E08180C3B7F72160÷÷00f7247
A1E18181EFBC9DFF1D2161=ff1d65309
A1E28182E289A022602162≠22608800
A1E38183EFBC9CFF1C2163<ff1c65308
A1E48184EFBC9EFF1E2164>ff1e65310
A1E58185E289A622662165≦22668806
A1E68186E289A722672166≧22678807
A1E78187E2889E221E2167∞221e8734
A1E88188E288B422342168∴22348756
A1E98189E2998226422169♂26429794
A1EA818AE299802640216A♀26409792
A1EB818BC2B0B0216B°°00b0176
A1EC818CE280B22032216C′20328242
A1ED818DE280B32033216D″20338243
A1EE818EE284832103216E℃21038451
A1EF818FEFBFA5FFE5216F¥ffe565509
A1F08190EFBC84FF042170$ff0465284
A1F18191EFBFA0FFE02171¢ffe065504
A1F28192EFBFA1FFE12172£ffe165505
A1F38193EFBC85FF052173%ff0565285
A1F48194EFBC83FF032174#ff0365283
A1F58195EFBC86FF062175&ff0665286
A1F68196EFBC8AFF0A2176*ff0a65290
A1F78197EFBCA0FF202177@ff2065312
A1F88198C2A7A72178§§00a7167
A1F98199E2988626062179☆26069734
A1FA819AE298852605217A★26059733
A1FB819BE2978B25CB217B○25cb9675
A1FC819CE2978F25CF217C●25cf9679
A1FD819DE2978E25CE217D◎25ce9678
A1FE819EE2978725C7217E◇25c79671
A2A1819FE2978625C62221◆25c69670
A2A281A0E296A125A12222□25a19633
A2A381A1E296A025A02223■25a09632
A2A481A2E296B325B32224△25b39651
A2A581A3E296B225B22225▲25b29650
A2A681A4E296BD25BD2226▽25bd9661
A2A781A5E296BC25BC2227▼25bc9660
A2A881A6E280BB203B2228※203b8251
A2A981A7E3809230122229〒301212306
A2AA81A8E286922192222A→21928594
A2AB81A9E286902190222B←21908592
A2AC81AAE286912191222C↑21918593
A2AD81ABE286932193222D↓21938595
A2AE81ACE380933013222E〓301312307
A2BA81B8E288882208223A∈22088712
A2BB81B9E2888B220B223B∋220b8715
A2BC81BAE28A862286223C⊆22868838
A2BD81BBE28A872287223D⊇22878839
A2BE81BCE28A822282223E⊂22828834
A2BF81BDE28A832283223F⊃22838835
A2C0879CE288AA222A2240∪*81BE222a8746
A2C1879BE288A922292241∩*81BF22298745
A2CA81C8E288A72227224A∧22278743
A2CB81C9E288A82228224B∨22288744
A2CCFA54EFBFA2FFE2224C¬*81CAffe265506
A2CD81CBE2879221D2224D⇒21d28658
A2CE81CCE2879421D4224E⇔21d48660
A2CF81CDE288802200224F∀22008704
A2D081CEE2888322032250∃22038707
A2DC8797E288A02220225C∠*81DA22208736
A2DD8796E28AA522A5225D⊥*81DB22a58869
A2DE81DCE28C922312225E⌒23128978
A2DF81DDE288822202225F∂22028706
A2E081DEE2888722072260∇22078711
A2E18791E289A122612261≡*81DF22618801
A2E28790E2899222522262≒*81E022528786
A2E381E1E289AA226A2263≪226a8810
A2E481E2E289AB226B2264≫226b8811
A2E58795E2889A221A2265√*81E3221a8730
A2E681E4E288BD223D2266∽223d8765
A2E781E5E2889D221D2267∝221d8733
A2E8FA5BE288B522352268∵*81E622358757
A2E98792E288AB222B2269∫*81E7222b8747
A2EA81E8E288AC222C226A∬222c8748
A2F281F0E284AB212B2272Å212b8491
A2F381F1E280B020302273‰20308240
A2F481F2E299AF266F2274♯266f9839
A2F581F3E299AD266D2275♭266d9837
A2F681F4E299AA266A2276♪266a9834
A2F781F5E280A020202277†20208224
A2F881F6E280A120212278‡20218225
A2F981F7C2B6B62279¶00b6182
A2FE81FCE297AF25EF227E◯25ef9711
A3B0824FEFBC90FF1023300ff1065296
A3B18250EFBC91FF1123311ff1165297
A3B28251EFBC92FF1223322ff1265298
A3B38252EFBC93FF1323333ff1365299
$sp=" ";
$lists="";
open(xIN,"codetable.cgi");
while( ($blocks=<xIN>) ){
	$blocks=~s/\n//g;
	$blocks=~s/\xd//g;
	$blocks=~s/\s+/$sp/g;
	@stack=split(/\s+/,$blocks);
	$lists.="&lt;tr&gt;";
	$lists.="&lt;td&gt;".$stack[0]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[1]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[2]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[3]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[4]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[5]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[6]."&lt;/td&gt;";
	$lists.="&lt;td&gt;".$stack[7]."&lt;/td&gt;";
	$lists.="&lt;/tr&gt;\r";
}
close(xIN);

open(xOT,">c_codetable.cgi");
print xOT $lists;
close(xOT);

print <<"EOM";
$revers_str
<textarea cols="110">$lists</textarea>
EOM
[box color=”lgray” icons=”fa-fcod”] 参考サイト:http://www.takeash.net/wiki/?Perl%2F%E6%96%87%E5%AD%97%E3%82%B3%E3%83%BC%E3%83%89 [/box]
# UTF-8 <-> 16進 変換
# utf8-hex.pl
# このスクリプトは、文字コード:UTF8N, 改行:LF として保存すること。
 
use strict;
use warnings;
use utf8;
use Encode;
use MIME::Base64;
 
my $utf8str = "ABCあいうえお";
my $hexstr = "414243E38182E38184E38186E38188E3818A";
my $b64str = "QUJD44GC44GE44GG44GI44GK";
 
open( OUT, ">:utf8", "output.txt" ) || die( "can't open 'output.txt'.\n" );
 
printf OUT ( "utf8:\t'%s'\n",    $utf8str );
printf OUT ( "->hex:\t'%s'\n",    &Utf8ToHex( $utf8str ) );
printf OUT ( "hex:\t'%s'\n",    $hexstr );
printf OUT ( "->utf8:\t'%s'\n",    &HexToUtf8( $hexstr ) );
printf OUT ( "utf8:\t'%s'\n",    $utf8str );
printf OUT ( "->B64:\t'%s'\n",    &Utf8ToB64( $utf8str ) );
printf OUT ( "B64:\t'%s'\n",    $b64str );
printf OUT ( "->utf8:\t'%s'\n",    &B64ToUtf8( $b64str ) );
 
close( OUT );
 
exit();
 
sub Utf8ToHex
{
    my( $src ) = @_;
    return unpack( "H*", encode( "utf8", $src ) );
}
 
sub HexToUtf8
{
    my( $src ) = @_;
    return decode( "utf8", pack( "H*", $src ) );
}
 
sub Utf8ToB64
{
    my( $src ) = @_;
    return encode_base64( encode( "utf8", $src ), "" );
}
 
sub B64ToUtf8
{
    my( $src ) = @_;
    return decode( "utf8", decode_base64( $src ) );
}
&#数字; を sjis に変換する過程
    $v6="&#12446;";   
    $v64=chr($v6);
    $v65= encode('utf-8', $v64);
    $v66=strcode_conv("utf8N2sjis",$v65);
    # 結果は「ゞ」
pack(型1,.. ,文字1,…)

型は、値の順番と型を以下のように与えます。
後に数字をつけて繰り返し回数を指定できます。

A 空白がつめられたアスキ文字列
a ヌルがつめられたアスキ文字列
c signed char 型の値
C unsigned char 型の値
s signed short 型の値
S unsigned short 型の値
i signed int 型の値
I unsigned int 型の値
l signed long 型の値
L unsigned long 型の値
n “network” オーダーの short
N “network” オーダーの long
f ネイティブフォーマットの単精度浮動小数
d ネイティブフォーマットの倍精度浮動小数
p 文字列へのポインタ
v “VAX”(little-endian) オーダーの short
V “VAX”(little-endian) オーダーの long
x ヌルバイト
X バイトのバックアップ
@ 絶対位置へのヌルの埋め込み
u uuencode された文字列
b ビット文字列 (ビットは昇順、 vec() と同様)
B ビット文字列 (ビットは降順)
h 16進文字列 (下位の2バイトが先)
H 16進文字列 (上位の2バイトが先)

スポンサーリンク

関連記事一覧