Ruby (1.9.3) と Powershell に問題があります。
ポーランド語の文章を処理するインタラクティブなコンソール アプリを作成する必要があります。私は助けられて、ポーランド語の分音記号を含む ARGV 要素を取得できましたが、標準入力が思い通りに機能しません。
コード図:
# encoding: UTF-8
target = ARGV[0].dup.force_encoding('CP1250').encode('UTF-8')
puts "string constant = dupą"
puts "dupą".bytes.to_a.to_s
puts "dupą".encoding
puts "target = " +target
puts target.bytes.to_a.to_s
puts target.encoding
puts target.eql? "dupą"
STDIN.set_encoding("CP1250", "UTF-8")
# the line above changes nothing, it can be removed and the result is still the same
# I obviously wanted to mimic the ARGV solution
target2 = STDIN.gets
puts "target2 = " +target2
puts target2.bytes.to_a.to_s
puts target2.encoding
puts target2.eql? "dupą"
出力:
string constant = dupą
[100, 117, 112, 196, 133]
UTF-8
target = dupą
[100, 117, 112, 196, 133]
UTF-8
true
dupą //this is fed to STDIN.gets
target2 = dup
[100, 117, 112]
UTF-8
false
どうやら Ruby は STDIN.gets から 4 番目の文字を取得しないようです。のような長い文字列を記述してdupąlalala
も、プログラム内には最初の 3 バイトしか表示されません。
- バイトを列挙してgetcでループしようとしましたが、Rubyに到達していないようです(どこで失われますか?)
- 私はchcp 65001を使用しました(何も変わっていないようです)
$OutputEncoding を [Console]::OutputEncoding; に変更しました。次のようになります。
IsSingleByte : True BodyName : ibm852 EncodingName : Środkowoeuropejski (DOS) HeaderName : ibm852 WebName : ibm852 WindowsCodePage : 1250 IsBrowserDisplay : True IsBrowserSave : True IsMailNewsDisplay : False IsMailNewsSave : False EncoderFallback : System.Text.InternalEncoderBestFitFallback DecoderFallback : System.Text.InternalDecoderBestFitFallback IsReadOnly : True CodePage : 852
Consolas フォントを使用しています
Powershell でポーランド語の分音符号を正しく読み取るにはどうすればよいですか?