当前位置:网站首页>Left alignment function of Lua language (handwriting)
Left alignment function of Lua language (handwriting)
2022-07-28 19:36:00 【h799710】
One 、 Preface :
lua The tabs of are still not strong enough , When a line is very big , It's all messed up behind . This language is not like python There are also rich libraries that can be called . Can't , Write one by hand .
Two 、 The code is as follows :
The logic is simple , Is to traverse the data first , Record the maximum length of each column .
And then according to The maximum length of the front row - Specific data length Get the blank space you need to fill ;
-- Concatenate a two-dimensional array into a string in the form of left alignment and return
function leftAlignString(data)
local data2 = {
}
local colLenList ={
}
local len, vlen = #data[1]
for i, v in ipairs(data) do
data2[i] = {
}
for vi, vd in ipairs(v) do
if type(vd) ~= "string" then
vd = tostring(vd)
end
data2[i][#data2[i] + 1] = vd
if vi ~= len then
data2[i][#data2[i] + 1] = ""
-- if i == 1then
-- colLenList[vi] = math.max(colLenList[vi] or 0, #vd / 3 * 2 + 4)
-- else
-- if #vd % 2 == 1 then
-- vlen = #vd + 1
-- else
vlen = #vd
-- end
colLenList[vi] = math.max(colLenList[vi] or 0, vlen + 2)
-- end
else
data2[i][#data2[i] + 1] = "\n"
end
end
end
-- Fill in the blanks
function bEmpty(count)
local str = ""
local fourEmpty = " ";
while count > 0 do
if count >= 4 then
str = str .. fourEmpty
count = count - 4
else
str = str .. " "
count = count - 1
end
end
return str
end
local empty = 0
for i, v in ipairs(data2) do
for k = 1, (len - 1) * 2 - 1, 2 do
-- if i == 1 then
-- -- print(v[k], k, colLenList[math.ceil(k / 2)], #v[k] / 3 * 2)
-- data2[i][k + 1] = bEmpty(colLenList[math.ceil(k / 2)] - #v[k] / 3 * 2)
-- else
-- print(v[k], k, colLenList[math.ceil(k / 2)], #v[k])
data2[i][k + 1] = bEmpty(colLenList[math.ceil(k / 2)] - #v[k])
-- end
end
data2[i] = table.concat(v)
end
return table.concat(data2)
end
local data = {
{
"index", "itemID", "randValue", "changeWeight", "initWeight", "isCompenate", "compenateData"},
{
1,52301,357229,1000000,1000000,false,"{}"},
{
1,52301,357229,1000000,1044400000,false,"{}"},
{
1,52301,357229,100000440,1000000,false,"{}"},
{
1,52301,357444229,1000000,1000000,false,"{}"},
{
2,51302,502332,26000,1875, false, "{}"},
}
data2 = leftAlignString(data)
print(data2)
3、 ... and 、 ending
The logic is simple , It took a little time to write . Just use what you need
If this method is aligned with Chinese, there will still be some deviation , The comments in the code are Slightly correct the deviation Methods , If you cancel the comment, you can use .
边栏推荐
- 英语文章翻译-英语文章翻译软件-免费批量翻译
- C language cycle sentence strengthening exercises
- Prometheus部署
- MySQL8 Status Variables: Internal Temporary Tables and Files
- 华为入股南京芯视界,布局固态激光雷达芯片领域
- App自动化测试是怎么实现H5测试的
- CVPR21-无监督异常检测《CutPaste:Self-Supervised Learning for Anomaly Detection and Localization》
- Update of objects in ES6
- App自动化测试是怎么实现H5测试的
- shared_ptr 和 make_shared 的使用
猜你喜欢

VAE:变分自编码器的理解与实现

Cvpr19 - adjust reference dry goods bag of tricks for image classification with revolutionary neural network

Getting started with saltstack

Pagoda panel construction novel CMS management system source code measurement - thinkphp6.0

在矩池云快速安装torch-sparse、torch-geometric等包

Nips18 (AD) - unsupervised anomaly detection using geometric transformations using geometric augmentation

source insight项目导入和使用教程

BLDC 6-step commutation simulink

SaltStack配置管理

Business visualization - let your flowchart "run" (4. Actual business scenario test)
随机推荐
Dockler的基础用法
With the help of panel industry innovation, will FPGA become the best choice for TCON?
[solved] ac86u ml revision firmware virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements
彻底理解位运算——左移、右移
文章翻译软件-批量免费翻译软件支持各大翻译接口
Search problems and technologies
Kotlin Android development novice tutorial
Image processing web application development tutorial
[notes] Apocalypse: list of practical experience and reflection of product managers
NDK series (5): from introduction to practice, JNI explodes the liver and explains everything in detail!
我的第二次博客——C语言
Swing事件处理的过程是怎样的?
ardupilot软件在环仿真与在线调试
诺基亚扩大与英国电信的5G协议,将成其最大无线接入设备供应商
Pytorch:快速求得NxN矩阵的主对角线(diagonal)元素与非对角线元素
用于异常检测的Transformer - InTra《Inpainting Transformer for Anomaly Detection》
【笔记】《结网:互联网产品经理改变世界》
Adobe Flash player 34.0.0.92 and available version modification methods (2021-01-23
11、 学习MySQL UNION 操作符
这个客制化键盘,秀翻我了~