ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Pattern matching non-English language characters (https://www.esoui.com/forums/showthread.php?t=4665)

Phinix 04/27/15 07:11 PM

Pattern matching non-English language characters
 
Hello all,

I am currently looking for a semi-elegant method of matching all letters that are not special language characters like ä, ë, ö, ü, etc. and have been having some trouble.

At first I tried :gsub("%w", string.upper, 1) to replace the first letter of a string with a capital, however this caused any of the above special language characters to become "xx."

I then tried string.sub(teststring, 1, 1) to get just the first character of a string, and it seems these special characters are using 2 (sometimes more?) characters, probably an escape code and a number, to render the actual symbol, so again, I ended up with just "x".

Is there a way to have lua only match the first character in a string if it is a letter and NOT one of these special letters?

Phinix 04/27/15 07:34 PM

I even tried this:

Code:

if string.sub(langtext, 1, 1) ~= "x" or "xx" then
        langtext = langtext:gsub("%w", string.upper, 1)
end

Still just ends up x's. :confused:

Phinix 04/27/15 08:16 PM

I figured it out... sort of.

I created a table (Alpha) with all standard alpha characters then did

Code:

for k,v in pairs(Alpha) do
        if string.sub(langtext, 1, 1) == v then
                langtext = langtext:gsub("%w", string.upper, 1)
                break
        end
end


Phinix 04/27/15 08:47 PM

My Argonian name is "Converses-With-Reflection." :D

Sasky 04/27/15 08:54 PM

http://lua-users.org/wiki/LuaUnicode

In standard Lua, it's not easy. There are a couple pure-Lua libraries there that you could use if you needed to for unicode pattern matching (and other string functions).


All times are GMT -6. The time now is 11:02 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI