Jump to content

change text before the symbol


fairyoggy

Recommended Posts

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

Link to comment
  • Moderators

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 by IIYAMA
  • Like 1
Link to comment
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.

Link to comment
  • Moderators

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

 

  • Like 1
Link to comment

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

 

Link to comment
  • Moderators
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.

 

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