Ruby: Incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)

ruby出現錯誤訊息:Incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)

用force_encoding強迫指定編碼即可。for example,

sentence=row1[0].force_encoding('utf-8').gsub(reg,cor_array[count].force_encoding('utf-8')).strip
分類: ruby。這篇內容的永久連結

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *