fairyoggy Posted January 22, 2020 Posted January 22, 2020 There is a text, for example, [email protected] Let's say local a = "[email protected]" How do I make the letters in front of the characters @ replaced by the character * I think need to create a variable B with the condition of replacing the letters before the character, but how to do it? was [email protected] has become *****@hotmail.com How to do it?
#\_oskar_/# Posted January 22, 2020 Posted January 22, 2020 use string.gsub example addEventHandler("onClientRender", root,function() dxDrawText(string.gsub('hello','.','*') ..'@hotmail.com',400,400,200,200) end) or addEventHandler("onClientRender", root,function() local msg = 'hello' dxDrawText(msg:gsub('.','*') ..'@hotmail.com',400,400,200,200) end) سبحان الله وبحمده سبحان الله العظيم
fairyoggy Posted January 22, 2020 Author Posted January 22, 2020 18 minutes ago, #\_oskar_/# said: use string.gsub example addEventHandler("onClientRender", root,function() dxDrawText(string.gsub('hello','.','*') ..'@hotmail.com',400,400,200,200) end) or addEventHandler("onClientRender", root,function() local msg = 'hello' dxDrawText(msg:gsub('.','*') ..'@hotmail.com',400,400,200,200) end) and if in the second case local msg = "[email protected]" How then to replace the letters with the characters before the character @
Moderators IIYAMA Posted January 22, 2020 Moderators Posted January 22, 2020 (edited) See https://wiki.multitheftauto.com/wiki/Split http://Lua-users.org/wiki/StringLibraryTutorial string.len string.rep local emailParts = split("[email protected]", "@") iprint(emailParts[1]) iprint(emailParts[2]) iprint(emailParts[1] .. "@" .. emailParts[2]) iprint(string.rep("*", string.len(emailParts[1])) .. "@" .. emailParts[2]) Edited January 22, 2020 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
fairyoggy Posted January 22, 2020 Author Posted January 22, 2020 18 minutes ago, IIYAMA said: See https://wiki.multitheftauto.com/wiki/Split http://Lua-users.org/wiki/StringLibraryTutorial string.len string.rep local emailParts = split("[email protected]", "@") iprint(emailParts[1]) iprint(emailParts[2]) iprint(emailParts[1] .. "@" .. emailParts[2]) iprint(string.rep("*", string.len(emailParts[1])) .. "@" .. emailParts[2]) @IIYAMA Ok, everything is fine. Another question, but how to use something like: [email protected] *****[email protected] I mean, so that the last three characters before the sign do not change.
Moderators IIYAMA Posted January 22, 2020 Moderators Posted January 22, 2020 I am not a string reg prof, but it works... local theString = "254646" local length = string.len(theString) local visibleCount = math.max(length - 2, 0) print(string.rep("*", string.len(string.sub(theString, 1, visibleCount))) .. string.sub(theString, visibleCount, length)) 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
fairyoggy Posted January 23, 2020 Author Posted January 23, 2020 and one more question, I can’t find an answer to it For example, I have edit with text edit = guiCreateEdit(11, 40, 181, 27, "", false, window1) button = guiCreateButton(10, 195, 182, 27, "button", false, window1) local test = "123456" local check = guiGetText(edit) guiSetText(edit,test) addEventHandler("onClientGUIClick", root, function() if source == button then end end) What do I need to write on the button? The "test" variable is just an example. How do I delete the most recent character in edit? was 123456 after press button has become 12345 next time 1234 , 123 , 12, 1 and empty edit
Moderators IIYAMA Posted January 23, 2020 Moderators Posted January 23, 2020 3 hours ago, slapztea said: How do I delete the most recent character in edit? See string.sub from my previous reply. It is used to select a range of characters. So if you know the length with string.len , then you can select a shorter range of characters. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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