Jump to content

about gsub, gmatch


Rouzbeh

Recommended Posts

Posted

hi, i want a code to get replace characters between "[ ]" from playername

like: [clan]playername to playername

delete "[x]" from playername

Posted (edited)
function getPlayerNameWithoutTags(player) 
  local name = getPlayerName(player) 
  return string.gsub(name, "\[.*\]", "") 
end 

Edit: I failed with escaping. Sorry. The slashes (\) should be percent symbols (%).

Edited by Guest
  • MTA Team
Posted

The pattern is wrong, here is the fix:

function getPlayerNameWithoutTags(player) 
    return getPlayerName(player):gsub("%[.*%]", "") 
end 
  

function getPlayerNameWithoutTags(player) 
  local name = getPlayerName(player) 
  return string.gsub(name, "\[.*\]", "") 
end 

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...