Created
October 16, 2023 17:59
-
-
Save diazvictor/e47d44194f22c5b37d19bd83d1c768fc to your computer and use it in GitHub Desktop.
A truncate string function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[-- | |
@package Solus Frontend | |
@filename truncate.lua | |
@version 1.0 | |
@author Díaz Urbaneja Víctor Eduardo Diex <victor.vector008@gmail.com> | |
@date 04.01.2021 19:53:44 -04 | |
@see https://github.com/diazvictor/solus-organizer/blob/solus-new/test/truncate.lua | |
]] | |
local str = "Donkey Kong Country 3 - Dixie Kong's Double Trouble.sfc" | |
-- make in 34min | |
function string.truncate(str, max, min) | |
local t, s, max, min = {}, str, max or 20, min or 0 | |
if #str > min then | |
for w in string.gmatch(str, ".") do | |
table.insert(t, w) | |
if #t > max then | |
break | |
end | |
end | |
s = ('%s...'):format(table.concat(t)) | |
return s | |
else | |
return s | |
end | |
end | |
-- Donkey Kong Country 3... | |
print(str:truncate()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment