Jump to content

[Help] Decompose


HunT

Recommended Posts

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

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:

27ds1z.jpg

Link to comment

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:

c4pfwx.jpg

Link to comment
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:

c4pfwx.jpg

Thank you really helpful.

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