. β’, UTF-8. , , , Ruby , IBM437 ( Windows).
:
>> input = "β’"
=> "β’"
>> input.encoding
=> #<Encoding:UTF-8>
>> input.force_encoding 'ibm437'
=> "\xE2\x84\xA2"
, force_encoding , . , , ( ).
- β’ UTF-8, Ruby (Watir, , ):
>> web_page = 'β’'
=> "β’"
>> web_page.encoding
=> #<Encoding:UTF-8>
, , , :
>> web_page.include? input
Encoding::CompatibilityError: incompatible character encodings: UTF-8 and IBM437
from (irb):11:in `include?'
from (irb):11
from /Users/matt/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
ASCII (.. , 128), . UTF-8 IBM437 ASCII , ASCII. , β’.
, Ruby, . :
>> input.force_encoding 'utf-8'
=> "β’"
, , . ( , ):
input = File.read("input_file.txt", :encoding => "utf-8")
, , - , Ruby .
:
>> web_page.include? input
=> true
encode . , . , UTF-8, IBM437:
>> input.force_encoding("utf-8").encode("IBM437", replace: nil)
Encoding::UndefinedConversionError: U+2122 from UTF-8 to IBM437
from (irb):16:in `encode'
from (irb):16
from /Users/matt/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
IBM437 β’, , , , . Ruby , . :undef, :
>> input.force_encoding("utf-8").encode("IBM437", :undef => :replace)
=> "?"
, force_encoding IBM437, UTF-8, ΞÀó:
>> input.force_encoding("IBM437").encode("utf-8", replace: nil)
=> "ΞÀó"
IBM437 Ruby, force_encoding . UTF-8 β’ 0xe2 0x84 0xa2, IBM437 , , UTF-8.
( , , . , .)