I´m at the very beginning with Ruby and give again and again this error

program.rb:6:in `gsub': broken utf-8 string (argumenterror)

when I'm trying this short code:

#coding:utf-8
 
temp=""
txtfile=File.open("8-3_tiedosto.txt","r");txtfile.each{|row|temp=temp+row};txtfile.close
 
temp = temp.gsub("Å", '')
puts temp

How to fix the code, as my environment does not allow to change the encoding statement at the first line? The original text in the file contains characters that I do not to
include to my final result, that should only contain ASCII 65..90 and
97..122. So I do not understand, what arguments should be given to gsub or how I shoul change my code?

I'm so sorry becaus ogf my stupidity.:$

Why not filter on the values you do wat to allow? Something like:

temp.gsub(/./) { |c|
   if (65..90).include? c.ord or (97..122).include? c.ord
      c
   else
      ""
   end
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.