Jump to content

Characters per line


SkatCh

Recommended Posts

Use this function:

function string.split ( str, count ) 
if count > string.len(str) then return false end 
local Linhas = {} 
local LC = 1 
    while LC < string.len ( str ) do 
        local linha = string.sub ( str, LC, LC + count -1 ):gsub(" ","") 
        table.insert ( Linhas, linha ) 
        LC = LC + count 
    end 
    return Linhas 
end 

Example:

myString = "1234567891011121314151617181920abcdefghi" -- 40 Characters 
  
allLines = string.split ( myString, 20 ) 
  
for _, line in ipairs ( allLines ) do 
    print ( line, line:len() ) 
end 
  
--[[ 
print: 
  
12345678910111213141    20 
51617181920abcdefghi    20 
--]] 

Link to comment

i don't know why didn't work with dxDrawText just one line appear , all what i need how to resize the dxRectangle

i tried this but did work.

just a part from my script:

  
-- Your example ofc with string.split function  
  
myString = "1234567891011121314151617181920abcdefghi" -- 40 Characters 
allLines = string.split ( myString, 20 ) 
  
function testDx() 
for _, line in ipairs ( allLines ) do 
  -- i add my code here to call the Dx function  
end 
addCommandHandler("test",testDx) 
  
-- And i add this to get the text width (it's correct or not) 
-- settings tabe (bla , bla) 
  
local X = dxGetTextWidth(string.gsub(line,"%#%x%x%x%x%x%x",""),settings.fontHeight,settings.font)+20*settings.scale 
local Y = dxGetFontHeight(settings.fontHeight,settings.font)*2+40*settings.scale 
  

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