dongliang1223 2015-12-04 16:23
浏览 43
已采纳

来自vsprintf的奇怪输出

I am trying to build a data-file with hardcoded strings...

So I am using this format:

Format: %a1s%06c%a20s%a30s%a30s%a30s%a30s%a7s%a13s%a20s%a8s%a1s%a1s%a1s%a30s%a14s%a1s%a2s%a39s%a8s%a30s%a2s%a13s%a5s%a7s%a1s%a8s%03c
Values:     "A",    "16",   "",     "",     "Ola Nordmann",     "Slottsgate 1",     "",     "1012",     "",     "",     "",     "",     "",     "P",    "",     "",     "I",    "",     "",     "",     "",     "",     "",     "",     "",     "",     "",     ""

Output: "1s20s30s30s30s30s7s13s20s8s1s1s1s30s14s1s2s39s8s30s2s13s5s7s1s8s"

My code:

    $aRecord = vsprintf($format, $values);
    return ['a-record' => $aRecord, 'values' => $values, 'format' => $format];

Probably just beacuse its pretty late and friday afternoon, hope some of you guys will se my mistake... Thanks! :)

EDIT:

Expected output:

A000016                                                  Ola Nordmann            Slottsgate 1                                                1012
  • 写回答

1条回答 默认 最新

  • doudui9516 2015-12-05 23:10
    关注

    So the solution whas pretty simple :P

    For left-aligning text, we need to use - instead of a

    printf("% -20s", "Richard");
    

    Hope this helps someone :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码