4

I use the MSN weatherservice. Now I have the following problem with string.match. All variables are filled except sWindRichtung. It equals nil.

sHumidity, rest = string.match(rest,"humidity=\"([^\"]+)\"(.*)");
sWind, rest = string.match(rest,"windspeed=\"([^\"]+)\"(.*)");
sWindRichtung, rest = string.match(rest,"winddisplay=\"([^\"]+)\"(.*)");

The string to filter is: humidity="77" winddisplay="11 km/uur N" windspeed="11"

I think that the character / is the problem.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Mark Munsterman
  • 169
  • 1
  • 3
  • 11

1 Answers1

5

You can parse the string in one go. Try this:

s = [[
humidity="77" winddisplay="11 km/uur N" windspeed="11"
]]

for k,v in s:gmatch('(%a+)="(.-)"') do
        print(k,v)
end

Of course, you may want to save the values in a table.

lhf
  • 70,581
  • 9
  • 108
  • 149