admin管理员组文章数量:1434956
For instance:
var a = " ";
var b = "";
b = a * 8;
alert(b +"this far to the right");
Note: I don't want to use   since ActiveX FSO will be used to write to a text file not html file. So it needs to be spaces only:
More thorough detail of what I'm trying to achieve:
I'm trying to get ActiveX FSO to write to a text file from an HTML order form once form is submitted it then proceeds to write up the order to a text file. The text file needs to be in certain format for Microsoft Dynamics to accept as an import sale.
Like this below shown as: customer code spaces item code spaces quantity spaces:
import.txt minus the string length with the slots = remaining spaces to fill.
C242299A *4 white spaces* 2890 *12 white spaces* 20 *6 white spaces*
[------------][----------------][--------]
12 char slots 16 char slots 8 char slots
write.js will create this import.txt file (this is the part I need help on)
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);
Supposed to create a text file that looks like this:
C242299A 2890 20
which will then be imported to Microsoft Dynamics.
But problem is it doesn't multiply the spaces it regards the spaces as 0/null :( Jquery solution weled.
For instance:
var a = " ";
var b = "";
b = a * 8;
alert(b +"this far to the right");
Note: I don't want to use   since ActiveX FSO will be used to write to a text file not html file. So it needs to be spaces only:
More thorough detail of what I'm trying to achieve:
I'm trying to get ActiveX FSO to write to a text file from an HTML order form once form is submitted it then proceeds to write up the order to a text file. The text file needs to be in certain format for Microsoft Dynamics to accept as an import sale.
Like this below shown as: customer code spaces item code spaces quantity spaces:
import.txt minus the string length with the slots = remaining spaces to fill.
C242299A *4 white spaces* 2890 *12 white spaces* 20 *6 white spaces*
[------------][----------------][--------]
12 char slots 16 char slots 8 char slots
write.js will create this import.txt file (this is the part I need help on)
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);
Supposed to create a text file that looks like this:
C242299A 2890 20
which will then be imported to Microsoft Dynamics.
But problem is it doesn't multiply the spaces it regards the spaces as 0/null :( Jquery solution weled.
Share Improve this question asked Apr 26, 2012 at 14:27 Quaking-MessQuaking-Mess 5254 gold badges12 silver badges23 bronze badges2 Answers
Reset to default 5To repeat a certain character multiple times use:
var max = 8;//times to repeat
var chr = "a";//char to repeat
console.log(new Array(max + 1).join(chr));//aaaaaaaa
Note that if you do this with spaces, they will mostly pact into a single one (but they are there).
You can use the <pre>
tag to show every single white space (demo)
With newer JS, you can use String.prototype.repeat()
along with template literals to achieve this.
const MAX_NUMBER_OF_SPACES = 5;
const EXAMPLE_TEXT = 'Hello World!';
for (let i = 0; i < MAX_NUMBER_OF_SPACES; i++) {
console.log(`${' '.repeat(i)}${EXAMPLE_TEXT}`);
}
版权声明:本文标题:jquery - How do you multiply blank spaces in javascript for use in ActiveX FSO Write() method - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745645137a2668091.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论