DakiLLa Posted June 23, 2009 Share Posted June 23, 2009 hi there. i got one problem: i have next: addCommandHandler( "test", function ( player ) local name = getPlayerName( player ); local i = string.find( name, "|", 1, plain ); if i then outputChatBox( "You got a char '|' in "..i.." index" ); end; end ); if i have a '|' symbol in playername, then how can i replace it, if i know it's index position? Link to comment
Lordy Posted June 23, 2009 Share Posted June 23, 2009 You can just use string.gsub to replace any occurrences of | if you want and you don't need to have the index position. http://lua-users.org/wiki/StringLibraryTutorial addCommandHandler("test", function (player) local nick = getPlayerName(player) local newnick = string.gsub(nick,"|","") -- searches for | and replaces with nothing, eg removes them setPlayerName(player, newnick) end ) Took the function names and syntax from memory so they might have some faults. But just for you to see. EDIT: Also in your code, the last argument of string.find has to be boolean (true or false), you just have 'plain' (eg a nil value) Link to comment
DakiLLa Posted June 24, 2009 Author Share Posted June 24, 2009 works good. thanks a lot 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