string.gsub not working

Hi,

I have the following piece of code in my app:

[lua] local p = 0
local p1 = 0

while true do
p = string.find(main," p1 = string.find(main,">",p);

if p == nil then break end

local r = string.sub(main,p,p1);
main = string.gsub(main,r,"");
print(main);
end[/lua]

I’m not sure why this isn’t working - r obviously exists in the string main - but the gsub function isn’t removing it from the main string.
Can anyone help?
[import]uid: 24641 topic_id: 34988 reply_id: 334988[/import]