本文簡要介紹ruby語言中 Encoding::InvalidByteSequenceError.source_encoding
的用法。
用法
source_encoding → encoding
將源編碼作為編碼對象返回。
請注意,如果轉換有多個步驟,則結果可能不等於編碼轉換器的源編碼。
ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP") # ISO-8859-1 -> UTF-8 -> EUC-JP
begin
ec.convert("\xa0") # NO-BREAK SPACE, which is available in UTF-8 but not in EUC-JP.
rescue Encoding::UndefinedConversionError
p $!.source_encoding #=> #<Encoding:UTF-8>
p $!.destination_encoding #=> #<Encoding:EUC-JP>
p $!.source_encoding_name #=> "UTF-8"
p $!.destination_encoding_name #=> "EUC-JP"
end
相關用法
- Ruby InvalidByteSequenceError.error_bytes用法及代碼示例
- Ruby InvalidByteSequenceError.incomplete_input?用法及代碼示例
- Ruby Integer.nobits?用法及代碼示例
- Ruby Integer lcm()用法及代碼示例
- Ruby Integer.self >=用法及代碼示例
- Ruby Integer.self >>用法及代碼示例
- Ruby Integer.next用法及代碼示例
- Ruby Integer.self ** numeric用法及代碼示例
- Ruby Integer integer?用法及代碼示例
- Ruby Integer.truncate用法及代碼示例
- Ruby Integer digits用法及代碼示例
- Ruby Integer divmod()用法及代碼示例
- Ruby Inflate.inflate用法及代碼示例
- Ruby Integer floor()用法及代碼示例
- Ruby Integer.sqrt用法及代碼示例
- Ruby Integer to_f用法及代碼示例
- Ruby Integer to_s用法及代碼示例
- Ruby Integer.bit_length用法及代碼示例
- Ruby InstructionSequence.base_label用法及代碼示例
- Ruby Integer times用法及代碼示例
- Ruby Integer truncate()用法及代碼示例
- Ruby Integer remainder()用法及代碼示例
- Ruby Integer.floor用法及代碼示例
- Ruby Integer.pred用法及代碼示例
- Ruby Integer.gcd用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 InvalidByteSequenceError.source_encoding。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。