_Perfect_ Posted October 23, 2018 Share Posted October 23, 2018 Hello I have a phone number system Each player has a seven-digit number To figure out what player's number is, we use the command / number And the server tells us: Number is : 1234567 Please teach me to work with strings so I can do the first three digits of the phone number from the last four digits. like this : Number is 123-4567 @Dimos7 @LilDawage @IIYAMA @KINGKHAN @MrTasty @Dimos7 @LilDawage @MrKAREEM plz help me Link to comment
Addlibs Posted October 23, 2018 Share Posted October 23, 2018 (edited) Depending on whether the 7 digit number is a real number or a string containing digits. function formatNumber(number) if (type(number)=="number") then -- if 'number' was a number rather than a string number = string.format("%07d", number) -- format the number into 7 digits padded by 0 from the front if the number is less than 1000000 end if (type(number)~="string") then return false end -- return a false and exit function if 'number' isn't a string at this point return string.sub(number, 1, 3) .. "-" .. string.sub(number, 4, -1) -- put characters 1 to 3, follow it with a dash, and characters 4+ end Edited October 23, 2018 by MrTasty Link to comment
_Perfect_ Posted October 23, 2018 Author Share Posted October 23, 2018 1 hour ago, MrTasty said: Depending on whether the 7 digit number is a real number or a string containing digits. function formatNumber(number) if (type(number)=="number") then -- if 'number' was a number rather than a string number = string.format("%07d", number) -- format the number into 7 digits padded by 0 from the front if the number is less than 1000000 end if (type(number)~="string") then return false end -- return a false and exit function if 'number' isn't a string at this point return string.sub(number, 1, 3) .. "-" .. string.sub(number, 4, -1) -- put characters 1 to 3, follow it with a dash, and characters 4+ end thanks 1 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