Albinix Posted April 9, 2011 Share Posted April 9, 2011 Hey I have a problem with "string.gsub" tag = "-|TG|-" name = "-|TG|-Albinix" subtag = string.gsub(name,tag,"") outputChatBox(subtag) -- outputs -> "|-Albinix" Why does it not delete the whole tag? Link to comment
Moderators Citizen Posted April 9, 2011 Moderators Share Posted April 9, 2011 Yeah that's strange, because I doesn't see any errors Maybe try this: function test( thePlayer, commandName ) local tag = "-|TG|-" local name = "-|TG|-Albinix" local subtag = string.gsub(tostring(name),tostring(tag),"") outputChatBox( tostring( subtag ) ) end addCommandHandler("test", test, false, false ) But it's almost the same Link to comment
Cadu12 Posted April 9, 2011 Share Posted April 9, 2011 Try this function test( thePlayer, commandName ) local tag = "-%|TG|%-" local name = "-|TG|-Albinix" local subtag = string.gsub(tostring(name),tostring(tag),"") outputChatBox( tostring( subtag ) ) end addCommandHandler("test", test, false, false ) Link to comment
Discord Moderators Zango Posted April 9, 2011 Discord Moderators Share Posted April 9, 2011 It is due to the magic characters in LUA: ( ) . % + - * ? [ ^ $ These characters have special meanings when used, and they change your string Cadu12's method works because he escapes the magic character - in your tag, by using %. For string.find, you can set the fourth argument to true and it will disregard string magic Link to comment
Cadu12 Posted April 9, 2011 Share Posted April 9, 2011 There is lua wiki for string.gsub http://www.lua.org/pil/20.1.html Lua is your friend Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now