0

Need help with function, which will used like string.sub, but will save color part of string

-- namespaces:
local stringf;
 
-- @class stringf
-- @desc string helper functions
stringf = {}; do
    -- @private
    local str = "\affffffffSample \aff8080ffText";
 
    -- @public
 
    -- @param {string} s Some Text
    -- @param {number} f How much to extract the string, float value from [0.0 - 1.0]
    -- @desc Extracting piece of text with saving hex colors
    function stringf:sub_hex(s, f)
        -- ...
    end
 
    -- @region Testing
    print(stringf:sub_hex(str, .5)); -- \affffffffSample
    print(stringf:sub_hex(str, .9)); -- \affffffffSample \aff8080ffTe
end
qhouz
  • 23
  • 4
  • 1
    please provide some own attempt to solve this problem. this is not a coding service. also don't expect us to reverse-engineer what the function should do. what word part? what is protection/skip? what is the purpose of the second parameter? why does 0.5 remove the last 8 characters from text? CHARGING it is not 5 characters long nor is it the 5th word, so what is the relation here? same for the second example. why does 0.3 remove 4 characters from the middle of the string? – Piglet Jan 13 '23 at 08:52
  • colors off, `EXPLOIT ` + `CHARGING` = 16 chars, 16*0.5 = 8 = `EXPLOIT `, 16*0.3 = 4.8 = 4 = `EXPL` – ESkri Jan 13 '23 at 09:14
  • I'm sure you can at least propose a few ideas after having read the Lua manual – Piglet Jan 13 '23 at 15:17
  • @Piglet i am already know lua, but i have problems with hard string manipulations like a substring with colored parts – qhouz Jan 30 '23 at 11:45
  • @ESkri yes you almost right, but this without color, that is why i am asking for – qhouz Jan 30 '23 at 11:47
  • don't post code via a pastebin link in a comment. edit your question instead. – Piglet Jan 30 '23 at 12:55

0 Answers0