Jump to content

string.gsub Problem


Albinix

Recommended Posts

  • Moderators

Yeah that's strange, because I doesn't see any errors :shock:

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...