LoginSignup
1
1

More than 5 years have passed since last update.

[lua5.1]文字列の桁揃え

Posted at

string.formatは数字の桁揃えしかできないので下記のように行った。

  1. 6文字以上のものは先頭から6文字までを抽出。
  2. 6文字以下のものは末尾にスペースを追加する。

という場合

  local len = string.len(str) -- 文字数をカウント
  if 6 > len then -- もし6文字より少なければ
    len = 6 - len -- その数を求めて
    for i = 1, len do -- 差の分だけスペースを追加する
      str = str.." "
    end
  end
  str = string.sub(str, 1, 6) -- 先頭から6文字までを抽出
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1