本文簡要介紹ruby語言中  Encoding::UndefinedConversionError.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 UndefinedConversionError.error_char用法及代碼示例
- Ruby UnboundMethod.original_name用法及代碼示例
- Ruby UnboundMethod.bind用法及代碼示例
- Ruby UncaughtThrowError類用法及代碼示例
- Ruby UnwindDetails.all_requirements用法及代碼示例
- Ruby UnboundMethod類用法及代碼示例
- Ruby UnwindDetails.reversed_requirement_tree_index用法及代碼示例
- Ruby UnboundMethod.parameters用法及代碼示例
- Ruby UnboundMethod.inspect用法及代碼示例
- Ruby UncaughtThrowError.new用法及代碼示例
- Ruby UnwindDetails.unwinding_to_primary_requirement?用法及代碼示例
- Ruby UnpackCommand.get_path用法及代碼示例
- Ruby UnwindDetails.sub_dependencies_to_avoid用法及代碼示例
- Ruby UnboundMethod.to_s用法及代碼示例
- Ruby UnboundMethod.owner用法及代碼示例
- Ruby UnboundMethod.clone用法及代碼示例
- Ruby UnboundMethod.arity用法及代碼示例
- Ruby URI.parse用法及代碼示例
- Ruby UID.change_privilege用法及代碼示例
- Ruby Util.unescape用法及代碼示例
- Ruby Util.url_encode用法及代碼示例
- Ruby UNIXSocket.new用法及代碼示例
- Ruby UNIXSocket.addr用法及代碼示例
- Ruby URI模塊用法及代碼示例
- Ruby UNIXServer.accept用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 UndefinedConversionError.source_encoding。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
