0

例えば:

var a = " ";
var b = "";
b = a * 8;
alert(b +"this far to the right");

注:ActiveX FSOはhtmlファイルではなくテキストファイルへの書き込みに使用されるため、&nbspは使用しません。したがって、スペースのみである必要があります。

私が達成しようとしていることのより完全な詳細:

ActiveX FSOにHTML注文フォームからテキストファイルへの書き込みを許可しようとしています。フォームが送信されると、注文をテキストファイルに書き込みます。Microsoft Dynamicsがインポート販売として受け入れるには、テキストファイルが特定の形式である必要があります。

以下のように表示されます:顧客コード スペース アイテムコード スペース 数量 スペース

import.txtからスロットを含む文字列の長さを引いたもの=埋める残りのスペース。

C242299A *4 white spaces* 2890 *12 white spaces* 20 *6 white spaces*
[------------][----------------][--------]
12 char slots    16 char slots   8 char slots

write.jsはこのimport.txtファイルを作成します(これは私が助けを必要としている部分です)

var customercode = document.getElementById("customercode").value;
var itemcode = document.getElementById("itemcode").value;
var quantity = document.getElementById("quantity").value;

var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile(path+"import.txt",8,true,0);
//customer code string length must be measured to determine remaining spaces 
//to fill before item code can be entered.
//you only have 12 character slots before the next string "item code" can be entered
var remainingSpaces = "";
remainingSpaces = 12 - customercode.length;
spacefill1 = " " * remainingspaces;
remainingSpaces = 16 - itemcode.length;
spacefill2 = " " * remainingSpaces;
remainingSpaces = 8 - quantity.length;
spacefill3 = " " * remainingSpaces;
s.WriteLine(customercode+spacefill1+itemcode+spacefill2+quantity+spacefill3);

次のようなテキストファイルを作成するとします。

  C242299A      2890       20

その後、MicrosoftDynamicsにインポートされます。

しかし、問題は、スペースを0/nullと見なすスペースを乗算しないことです:( Jqueryソリューションを歓迎します。

4

2 に答える 2

5

特定の文字を複数回繰り返すには:

var max = 8;//times to repeat
var chr = "a";//char to repeat

console.log(new Array(max + 1).join(chr));//aaaaaaaa

スペースでこれを行う場合、それらはほとんど単一のスペースに圧縮されることに注意してください(ただし、スペースは存在します)。

タグを使用して、<pre>すべての空白を表示できます ( demo )

于 2012-04-26T14:45:43.033 に答える