HunT Posted March 28, 2015 Share Posted March 28, 2015 Hi guys. How can I Decompose a value from the gui edit? Example : i have the value in the gui edit 12345 but i need 1 2 3 4 5 text = guiGetText ( guiEdit ) -- get the text v1, v2, v3, v4, v5 = using the text ? -- the gui edit have max 5 Length Tnx Link to comment
WhoAmI Posted March 28, 2015 Share Posted March 28, 2015 You can use string.sub Example local text = "12345" local v1 = string.sub ( text, 1, -5 ) local v2 = string.sub ( text, 2, -4 ) local v3 = string.sub ( text, 3, -3 ) local v4 = string.sub ( text, 4, -2 ) local v5 = string.sub ( text, 5, -1 ) print(v1 .. " " .. v2 .. " " .. v3 .. " " .. v4 .. " " .. v5) Output: Link to comment
WhoAmI Posted March 28, 2015 Share Posted March 28, 2015 Well, I made function for it if this string's length will be higher than 5. Look at this function decompse ( n ) if ( type ( n ) == "number" ) then local l = string.len ( n ) local t = { } for i=0,l do table.insert ( t, string.sub ( n, i + 1, ( l - i ) * (-1) ) ) end return t end end It returns table with decompsed numbers. Here is the proof: Link to comment
HunT Posted March 28, 2015 Author Share Posted March 28, 2015 Well, I made function for it if this string's length will be higher than 5. Look at this function decompse ( n ) if ( type ( n ) == "number" ) then local l = string.len ( n ) local t = { } for i=0,l do table.insert ( t, string.sub ( n, i + 1, ( l - i ) * (-1) ) ) end return t end end It returns table with decompsed numbers. Here is the proof: Thank you really helpful. 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