这些代码行在VBScript中做了什么?

时间:2017-02-28 07:30:19

标签: vbscript jython

我正在将它们转换为Jython脚本,我觉得它只是在末端删除空格

function test (strField)
  Dim re 
  Set re = New RegExp
  re.Pattern = "^\s*"
  re.MultiLine = False
  strField = re.replace(strField,"")
End Function

1 个答案:

答案 0 :(得分:3)

它使用VBScript中的RegExp对象检查传递到名为\s的{​​{1}} / Sub的变量开头的空格Function。一旦识别出空格,它就会使用strField方法从字符串的开头删除任何匹配的字符。

由于@ansgar-wiechersmentioned in the comments,它只是LTrim() function的所有空白实现。

我假设这应该是Replace()虽然(尚未测试但可能VBScript接受Function作为Fun的简写,而不是我的东西熟悉个人)考虑到这一点,它应该返回修改后的Function值作为函数的结果。还建议使用strField在操作失效后停止ByVal值。

strField

代码中的用法:

Function test(ByVal strField)
  Dim re 
  Set re = New RegExp
  re.Pattern = "^\s*"
  re.MultiLine = False
  strField = re.replace(strField,"")
  test = strField
End Function

输出:

Dim testin: testin = "             some whitespace here"
Dim testout: testout = test(testin)
WScript.Echo """" & testin & """"
WScript.Echo """" & testout & """"
相关问题