简体   繁体   English

如何在帖子内容中添加字符?

[英]How to add character to content of post?

In per posts, there are "oo/x/". 在每个帖子中,有“ oo / x /”。

How to add "0" before "x" if length(x) <10 ? 如果length(x)<10,如何在“ x”之前添加“ 0”?

Example: 例:

x=12345678 ; x = 12345678; length(x) = 8, so add "00" before x ===> x=0012345678 length(x)= 8,因此在x ===> x = 0012345678之前添加“ 00”

x=1234567 ; x = 1234567; length(x) = 7, so add "000" before x ===> x=0001234567 length(x)= 7,因此在x ===> x = 0001234567之前添加“ 000”

x=123456789 ; x = 123456789; length(x) = 9, so add "0" before x ===> x=0123456789 length(x)= 9,因此在x ===> x = 0123456789之前添加“ 0”

Do you understand ? 你理解吗 ? Sorry for my poor English ! 对不起,我的英语不好! Thank you very much ! 非常感谢你 !

In ANSI C: 在ANSI C中:

#include <stdio.h>

int main()
{
   int x = 12345678;
   printf("x = %010d\n", x);
   return 0;
}

Note the %010d, where % is a format specifier which will be replaced by a following argument, the 0 being a flag which pads 0's, and the maximum number of 0's. 请注意%010d,其中%是格式说明符,它将由以下参数替换,0是填充0的标志,最大数目为0。

Read more here - printf() 在此处阅读更多内容-printf()

If this is for Java, you can do this using System.out.printf(); 如果这是针对Java的,则可以使用System.out.printf();来完成。 in the same way. 以同样的方式。

EDIT : Now that it's clear on where the problem domain lies (in this case WordPress), then you can use PHP. 编辑 :现在很清楚问题域位于何处(在本例中为WordPress),那么您可以使用PHP。

See the following barebones example using sprintf() in PHP: 请参阅以下在PHP中使用sprintf()的准系统示例:

<?php
   // ...
   $x = 12345678;
   $yourString = sprintf(nl2br("x = %010d\n"), $x); 
   // ...

   echo $yourString;
?>

How you are printing out the values depends on how you're retrieving your information and your layout, but this is a simple example that answers the question. 如何打印出值取决于您如何检索信息和布局,但这是一个简单的示例,可以回答问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM