🔲 Text Padding Tool
填充选项
按字节计算时,若填充字符本身超过剩余字节,会宁可少填也不溢出,结果可能短于目标宽度;按字符计算时按用户可见字符簇计数,emoji 不会被拆开。
📋 填充结果
请输入文本...
📚 深度解析:文本填充对齐
💡 常见使用场景
- 固定宽度输出:把不等长字符串左补零或右补空格,便于对齐与排序。
- 报表与编号:订单号补零到固定位(000123),字典序即数值序。
- 终端表格:用空格填充使列对齐。
编号补零到 6 位
输入「123」,左补零到 6 位得「000123」;配合排序时「000123」自然小于「000999」,避免「123」排在「99」后的乱序。
❓ 常见问题(FAQ)
- 中文怎么算宽度?
- 中文按 2 字符宽、英文 1 宽;填充对齐时若要视觉对齐需用支持 CJK 宽度的计算,否则出现错位。
- 超出目标长度呢?
- 超长默认截断或原样保留(可选);补零编号建议先确认最大位数,避免截断高位。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Padding definition | padding appends a fill character on one or both sides up to a target width | Unicode UAX #44, character database |
| Display width | fullwidth characters occupy two columns so width based padding differs from count based | Unicode UAX #11, East Asian width |
| Fixed width alignment | tabular output aligns columns to fixed widths and overflow is left intact | W3C CSS Text Level 3, text-align |
⚠️ 使用说明与注意事项
- 本工具纯前端运行,数据不会上传到服务器
- 建议在主流浏览器(Chrome/Safari/Firefox/Edge)中使用
- 计算结果仅供参考,请以实际应用场景为准