我在 JS 中有一个工作函数
function countWords(s){
s = s.replace(/(^\s*)|(\s*$)/gi,""); //modified trim function
s = s.replace(/[ ]{2,}/gi," ");
s = s.replace(/\n /,"\n");
return s.split(' ').length;
}
问题是当我更改为 ASP 时,它似乎不起作用:
Sub formatText(a)
a = Replace("/(^\s*)|(\s*$)/gi",a,"")
a = Replace("/[ ]{2,}/gi",a,"")
a = Replace("/\n /",a,"\n")
return a
End Sub
它从函数中什么也不返回,如何解决这个问题?谢谢
变成
'regEx initialization
Dim regEx
set regEx = New RegExp 'Creates a regexp object
regEx.IgnoreCase = True 'Set case sensitivity
regEx.Global = True 'Global applicability
'trim input text
Sub formatText(a)
a = Replace("(^\s*)|(\s*$)",a,"")
a = Replace("[ ]{2,}",a,"")
regEx.IgnoreCase = False 'Set case sensitivity
regEx.Global = False 'Global applicability
a = Replace("\n ",a,"\n")
return a
End Sub
仍然没有运气请帮助..