Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved]Umlaut reading problems

Status
Not open for further replies.
I have a problem using the 'File.open()' and 'file.readlines' commands. I somehow managed to get this whole file reading thing done, but using the above two commands (dunno which one) won't read the umlauts (ä, ö, ü; which are ä , ö , and ü in html, just in case you can't read them) out of the files. For example, if I'd write "Müller" (Müller), the output'd be "Mller"... the umlauts work in the rest of the game, so I can say fairly sure that the file reading is the problem's cause.


What I'd like to get from this post is one of the following things:

a) a method to make RGSS read the umlauts

b) a method to search the readed string in RGSS for something like #o and convert it to ö (ö) after reading (something like replace("#o", "ö") would be nice).

c) another method I didn't thought about that'll let me read the umlauts...


Thanks in advance.
 
First of all, if you're using a .txt file, depending on the encoding the programm could possibly not be able to read dieresises (Umlauts). So you could try changing the encoding to see if it changes anything.

if you want to create a method to replace #u with ü for example, you could do it like this :

Code:
text = 'M#uller'
for i in 0...text.size
  letter = text[i..i]
  if letter == '#'
    text.slice!(i)
    case text[i..i]
    when 'u'
      text[i] = 'ü'
    when 'o'
      text[i] = 'ö'
    else
  end
end

p text # ==> "Müller"

note that this could be simplified, but that way you can easily understand what's going on.
 
Thanks for your help, changing the file encoding from ANSI to UTF-8 was the only thing to do... very nice, but still hard to figure out if you never had to touch this sneaky dropdown menu :P

Just out of curiosity and for maybe-future scripts: How would this code look like simlified and what would the code look like for whole string replacement (let's assume I won't just change things with a # before them).

And thanks for your help, of course.
 
Like this :

Code:
text = 'Müller'
ref = ['&aaml;', 'ü', '&ooml;']
val = ['ä', 'ü', 'ö']
for i in 0...ref.size
  text.gsub!(ref[i], val[i])
end
p text # ==> 'Müller'

You could also create a method for the String class :
Code:
class String
  def dieresis
    text = self.dup
    ref = ['&aaml;', 'ü', '&ooml;']
    val = ['ä', 'ü', 'ö']
    for i in 0...ref.size
      text.gsub!(ref[i], val[i])
    end
    return text
  end

  def dieresis!
    ref = ['&aaml;', 'ü', '&ooml;']
    val = ['ä', 'ü', 'ö']
    for i in 0...ref.size
      gsub!(ref[i], val[i])
    end
    return self
  end
end

string = 'Müller ist Bl&ooml;d.'
p string.dieresis # ==> 'Müller ist Blöd.'
p string # ==> 'Müller ist Bl&ooml;d.'
string.dieresis!
p string # ==> 'Müller ist Blöd.'
 
This topic has been resolved. If BlueScope or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top