Jim*_*son 1 string coldfusion whitespace concatenation append
我需要在字符串的末尾添加空格。
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 & ' '>
</CFLOOP>
Run Code Online (Sandbox Code Playgroud)
您可以使用 repeatString()
<cfset form.strInput = form.strInput & repeatString( ' ', max( 7-len(form.strInput), 0 ) ) />
Run Code Online (Sandbox Code Playgroud)
但是,请记住,如果您尝试在网页上显示多个连续空格,浏览器将只“显示”第一个。
| 归档时间: |
|
| 查看次数: |
298 次 |
| 最近记录: |