Here’s my code:
text = File.read('/Users/username/Desktop/text.txt')
replace = text.gsub('hai', 'hǎi')
File.open('/Users/username/Desktop/text.txt', "w") {|file| file.puts replace}
I am trying to run this script from my terminal, but it gives this error:
XXXX:Desktop username$ ruby replace.rb
replace.rb:2: invalid multibyte char (US-ASCII)
replace.rb:2: invalid multibyte char (US-ASCII)
replace.rb:2: syntax error, unexpected $end, expecting ')'
replace = text.gsub('hai', 'hǎi')
^
I actually want to replace lots of characters with accented characters in my CSV file which will later be exported to my MySQL database.
you can try putting
-Ku