--- 字符串分割 ---@param sep string ---@return table function string:split(sep) local sep, fields = sep or "\t",{} local pattern = string.format("([^%s]+)", sep) self:gsub(pattern, function(c) fields[#fields+1] = c end) return fields end --- 字符串直接转Number ---@param InStr string ---@param sep string ---@return int32 function string.splitToNumber(InStr, sep) local sep, fields = sep or "\t", {} local pattern = string.format("([^%s]+)", sep) InStr:gsub(pattern, function(c) fields[#fields+1] = tonumber(c) end) return fields end function string.formatTime(seconds, ShowMinutes, ShowHours) if ShowMinutes == nil then ShowMinutes = false end if ShowHours == nil then ShowHours = false end local hours = math.floor(seconds / 3600) local minutes = math.floor((seconds - hours * 3600) / 60) local remainingSeconds = seconds - hours * 3600 - minutes * 60 local ResTime = "" ResTime = ResTime .. ((hours > 0 or ShowHours) and string.format("%02d:", hours) or "") ResTime = ResTime .. ((minutes > 0 or hours > 0 or ShowHours or ShowMinutes) and string.format("%02d:", minutes) or "") ResTime = ResTime .. string.format("%02d", remainingSeconds) return ResTime end local RootPackagePath = UGCMapInfoLib.GetRootLongPackagePath() -- 获取一个文件的完整路径 function string.GetFullPath(InPath) if type(InPath) ~= "string" then return "" end if #RootPackagePath > #InPath or string.sub(InPath, 1, #RootPackagePath) ~= RootPackagePath then InPath = RootPackagePath..InPath end return InPath end function string.limit(str, size) if string.len(str) <= size then return str; end return string.sub(str, (-1 - size + 1), -1); end