cutstr

function cutstr( str, n ) --> left, right

Description

The functions splits a string at postion n in two pieces. The element at n will be part of the left sub string.

Parameters

str

The string that should be split.

n

The postion in the string where the cut happens.

Return Values

left

The left part of the string.

right

The right part of the string.

Code

--ZFUNC-cutstr-v1
local function cutstr( str, n ) --> left, right
   return str:sub( 1, n ), str:sub( n + 1, #str )
end

return cutstr

Examples

local t = require( "taptest" )
local cutstr = require( "cutstr" )

left, right = cutstr( "abc", 2 )
t( left, "ab" )
t( right, "c" )

t()