Ruby and special characters
-
hi,
i get ifc-fields from german cad-programs, which have "Ă€, Ă, " etc. in the ifc-descriptions.
ho can i handle this in ruby, when i want to check them?
example:
iterate key / value...
if key == "FlÀche" then...saving this the ruby do not work...
thanx
stan -
In the very first line of your Ruby RB file add this.
# encoding; UTF-8This should ensure your own code is properly formatted.
Additionally, if needed, to force your 'read' ifc data file's text into the correct encoding try this...
text_string_read from_ifc_file.force_encoding("UTF-8") -
thanx a lot. perfect-:)
-
hi tig,
first : thanx for your help.
but
i am doing something wrong.i placed the utf info at the very first line (above "Module")
` # encoding: UTF-8
module ZF_ifc#########################################################################################
class ZF_BIM_version
#######################################`but i still get
Error:
#<SyntaxError: C:/Users/zdene/AppData/Roaming/SketchUp/SketchUp 2023/SketchUp/Plugins/zf_areal3d_bim/areal3d_bim_prg.rb:6743: invalid multibyte char (UTF-8)>so i cannot search in keys for german letters (Ă€,ĂŒ,ö).
in the key of the hash there is an "Ă€"
i want to check with ruby, if there is an "Ă€" in ite key:
elsif tt[0].to_s.include?("Länge")elsif tt[0].to_s.include?("Länge")elsif tt[0].to_s.include?("LĂ€nge")i just stick.....
stan
-
#<SyntaxError: C:/Users/zdene/AppData/Roaming/SketchUp/SketchUp 2023/SketchUp/Plugins/zf_areal3d_bim/areal3d_bim_prg.rb:6743: invalid multibyte char (UTF-8)>
Tells you the line where the error is...
Have you tried simply copy/pasting the same string with the Ă€ ĂŒ ö characters
into your script, so as to sidestep the issue ?
e.g.elsif tt[0].to_s.include?("LĂ€nge")an alternative format could be
elsif tt[0].to_s=~/LĂ€nge/If the RB is specifically defined as using UTF-8 then it should work...
-
the alternativ format is perfectly working !
thanx a lot for this, i di not know this syntax yet

stan
-
hi tig,
just a small add to this toppic:situation:
i imported a ifc from a german cad with special chatacters "Ă€,ö,ĂŒ..."
in the "key" of the ifc-parameterwe solved the handling for ruby by using ift-8
so far, so good.
now i tried to export this file from skp to ifc
and reimport ( to see, if my attributes are passed correctly).can it be , that sketchup exports the code of the special character in some special way?
in reimport the ifc-key contents the code itself now, not the original special character - somehow...
screenshots show the display in the original file and after the re-import.
i want to try to detect those codes by ruby again to be able to differ between areas, length and so on.
regards
stan


-
What text encoding does the original ifc file use ?
Once you know that you can try to convert the encoding of the final edited string you want to put into that file, encoding it into the appropriate format...
https://www.educative.io/answers/how-to-use-the-encoding-class-in-ruby
https://www.cloudbees.com/blog/how-ruby-string-encoding-benefits-developersThere are lots or resources on the http://www...
-
hi tig,
ok, if it depends on the encoding of the original file imported to skp, i will have to study it.
thanx and merry x-mas!stan
-
@tig said:
In the very first line of your Ruby RB file add this.
# encoding; UTF-8This should ensure your own code is properly formatted.
This magic comment does not ensure that the code file is saved as UTF-8 w/o BOM.
This must be set in whatever code editor is being used.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đ
Register LoginAdvertisement