[Closed] Special characters problem
Hello everybody.
I’m trying to make a script that will rename all the objects on the scene so there are no Croatian characters in the names. This turned out to be a problem since this:
if someString[cntr]==“đ” do someString[cntr]=“d”
…simply doesn’t work. When it compares someString[cntr] to “đ” it always turns out false. (And this is not the only problematic char)
I wanted to try comparing ascii charcodes, but I can’t find any function that extracts ascii code from a char value. Is there any other way I could to this?
I’d really appreciate help with this. Thanks
[size=2]if (bit.charAsInt someString[cntr])==144 then someString[cntr] = “E”
bit.charAsInt
bit.charAsHex…
You can use these functions but I don’t see Croation characters in the ascii table, maybe you have to use hex or something
[/size]
Thanks stuh505 for your help.
This is where the bug really shows itself. :deal:
All the problematic letters actually return 63 which is the ASCII code for “?”. :argh:
The only thing I can do is catch ascii 63, replace it with some other char and pass the new name with uniqueName to avoid repeating names.
Considering the problem solved
The funny thing is that this is not the case in Listener. There if I compare the single char to a string that cointains it (and reference the char in the string with it’s index) it returns true.
“đ” == “pđ”[2] ==> true
or I can assign it to a variable and then test, same thing happens:
test = “pđ”;“đ” == test[2] ==> true
Interesting, none the less… :surprised
I don’t know how to get croatian characters in the first place so I can’t test anything out…but if it is the case that you cannot get the ascii value but are able to check equality between them, you could write a function that checks for equality with a list of them in order to determine which letter to replace with
That’s basically my problem. I can check equality in the Listener, but I get a different result back from the script. Same code, different results :surprised
I’m guessing it’s because I’m comparing a variable to a constant. One of them changes to “?” while the other remains the wanted char. I’m guessing this happens to the constant, because in the end I get the name with the problem chars still in it, while the other chars are replaced ok. :curious:
The easiest thing would be to make our associates stop using Cro chars in the object names. So the bug is actually in the people I have to work with. No workarounds there :arteest:
Too bad I can’t make a script that’ll slap them around some if they try to use those again :applause:
Final version, replaces any non a-z,0-9 chars with a “_”:
for cntr = 1 to someString.count do
(
charAscii = bit.charAsInt someString[cntr]
if (charAscii<48 or (charAscii > 57 and charAscii < 65) or (charAscii>90 and charAscii<97) or charAscii>122) do someString[cntr] = “_”
)