如何重复空格 [英] How to repeat whitespace
问题描述
我试图获得如下所示的字符串:
[====]
为此,我使用以下代码:
'['+'='。repeat(4)+''.repeat(4)+']'
...但我只是得到 [====]
;也就是说,所有的空间都被压扁成一个。我在google chrome控制台中检查了这段代码,确实''.repeat(25)
只产生一个空格。我怎么让 repeat
真的产生多个空格?
我没有在手册。
浏览器折叠多个空格,为了强制它不使用 non-breaking spaces 。
因此,您可以使用
'& nbsp;'。repeat(4)
(它可以证明一个调试控制台不应该压缩空白,但在你的情况下它看起来就是这样)
I am trying to get a string like the following one:
[==== ]
For that purpose I am using this code:
'[' + '='.repeat (4) + ' '.repeat (4) + ']'
... but I just get [==== ]
; that is, all spaces are squashed into one. I checked this code in the google chrome console, and indeed ' '.repeat(25)
produces only one space. How do I make repeat
really produce more than one space?
I do not find anything related in the manual.
Browsers collapse multiple whitespace, in order to force it not to you can use non-breaking spaces.
Therefore, in your case you can use
' '.repeat(4)
(Its arguable that a debug console shouldn't collapse the whitespace, but in your case it seems it does)
这篇关于如何重复空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!