我已经在WSH中编写了几天的代码,就在最近,WScript.Echo()
方法开始只打印部分字符串,或者它会将字符串的末尾放在开头,这样它混乱不堪。我使用的是Win7 pro x64。这是包含损坏的Echo()
方法的函数:
function age() {
if ( !/\d*/.test(specimen[AGE]) || !/\d*/.test(comp[AGE]) ) {
WScript.Echo('ERROR: age value for specimen or comp not valid')
WScript.Sleep(10000);
WScript.Quit();
}
WScript.Echo("specimen[AGE] = ", specimen[AGE], " and comp[AGE] = ", comp[AGE])
ageAdjValue = ( parseInt(specimen[AGE]) * 250) - ( parseInt(comp[AGE]) * 250)
adjArray[AGE] = ageAdjValue;
//log adjArray
for (i=0; i < adjArray.length; i++) {
WScript.Echo(adjArray[i])
}
}
这是输出:
and comp[AGE] = 12
SKIP
SKIP
SKIP
SKIP
SKIP
0
0
?
0
0
0
2500
0
0
顶部的信息不包含标本[AGE]部分,而是有空格。
现在看看它是否是因为样本[AGE]元素中包含的内容,我将其更改为标本[ADDRESS],如下所示:
WScript.Echo("specimen[AGE] = ", specimen[ADDRESS], " and comp[AGE] = ", comp[AGE])
这是新的输出:
and comp[AGE] = 12ings Ct.
SKIP
SKIP
SKIP
SKIP
SKIP
0
0
?
0
0
0
2500
0
0
它将地址放在末尾而不是开头,只打印部分地址......
然后我注意到在specimen[ADDRESS]
之前的字符串中,字符串与变量不匹配......而对于它的地狱,我把它改为&#34;标本[ADDRESS] &#34;匹配,像这样:
WScript.Echo("specimen[ADDRESS] = ", specimen[ADDRESS], " and comp[AGE] = ", comp[AGE])
现在我完全不知道为什么......但是输出改为在最后包含2个额外的完整地址字符......
and comp[AGE] = 1263 Kings Ct.
SKIP
SKIP
SKIP
SKIP
SKIP
0
0
?
0
0
0
2500
0
0
当我使用+
运算符连接字符串而不是逗号时,会发生同样的事情。可能导致这种情况的原因是什么?
答案 0 :(得分:1)
(1)WScript.Echo&#39; ed字符串看似缺失部分的效果是由嵌入式&#34; \ r&#34;在数据中:
WScript.Echo("A", "BB", "CCC");
WScript.Echo("A\r", "BB", "CCC");
=>
A BB CCC
BB CCC
(2)检查嫌犯,引用&#39;数据:
WScript.Echo(">" + "A" + "<");
WScript.Echo(">" + "A\r" + "<");
=>
>A<
<A
(3)它永远不会是相同的&#39;当你WScript.Echo一个参数列表(空格分隔符)vs一个连接(没有空格分隔符):
WScript.Echo("A", "BB", "CCC");
WScript.Echo("A" + "BB" + "CCC");
=>
A BB CCC
ABBCCC
(4)/无论* / - 即通过RegExp在字符串中查找零或更多的whatevers - 在大多数情况下都是无用的:
WScript.Echo(/\d*/.test("full of sequences of zero or more digits"));
WScript.Echo(/\d+/.test("full of sequences of zero or more digits"));
WScript.Echo(/\d+/.test("full of 1 sequences of one or more digits"));
=>
-1
0
-1