小编Jim*_*son的帖子

在 Coldfusion 中为字符串添加空格

我需要在字符串的末尾添加空格。

ColdFusion 似乎会自动删除我尝试添加的任何空格,有时我会得到 1 个空格字符,但仅此而已。

我有一个输入字段,一个字符串,最长可达 7 个字符。如果输入少于 7 个字符,我要用空格填充结尾。

有谁知道使用coldfusion 实现这一点的快速、简单、直观的方法。尽可能少的代码是首选。

我尝试的一些解决方案是:

 #LEFT(FORM.strInput & '       ', 7)#

 #LEFT(FORM.strInput & '        0', 7)#

 #REPLACE(LEFT(FORM.strInput & 0000000, 7), '0', ' ', 'all')#

<CFLOOP FROM="1" TO="7 - LEN(FORM.strInput)">
  <CFSET FORM.strInput = FORM.strInput & ' '>
</CFLOOP>

<CFLOOP FROM="1" TO="7 - LEN(FORM.strInput)">
  <CFSET FORM.strInput = FORM.strInput & '&nbsp;'>
</CFLOOP>
Run Code Online (Sandbox Code Playgroud)

string coldfusion whitespace concatenation append

1
推荐指数
1
解决办法
298
查看次数

标签 统计

append ×1

coldfusion ×1

concatenation ×1

string ×1

whitespace ×1