View Single Post
09-27-22, 03:43 PM   #1
casualfetzer
A Defias Bandit
Join Date: Sep 2022
Posts: 3
Weird issues with string.match and encoding (I think)

Hey,

I'm trying to do some string pattern matching to pull out an m+ key level from the description from a Group Finder posting. However the matching seems to get some fairly odd results

Here is a snippet of the code from within a hook function registered to the LFGListSearchEntry_Update event

Code:
function DWMShook_LFGListSearchEntry_Update(entry, ...)

    local name = entry.Name:GetText() or "";

    local key_level = strmatch(name, "(%d+)")
    --Show the matched string and the original string it was matched from
    print(format("%s - key_level, %s - name", key_level, name))

    --Check strmatch functionality on string literal (i.e. not string from
    --Blizzard API
    print(strmatch("+21", "(%d+)"))

end
And this outputs
Code:
445 - key_level, +15 - name
21
I've read somehwere that all strings returned from Blizz APIs are encoded as UTF-8 and I guess this might be causing an issue due to the variable width of the character codes in UTF-8. Anyone come across this kind of issue before is there something super obvious I am missing. Feels like I'm missing something or that I'm doing something dumb (or both)

Cheers,
Fetzer
  Reply With Quote