开发者

how does vbscript evaluate string greater than string?

i'm converting some vbscript from an asp app and ran across a line in the form of

If sCode > "" Then

where I expect sCode to contain a string. i know enough vbscript to plod through it but i'm not sure of the behavior of some quirkier statements. c# will not accept that as a valid condition check. what is an equivalent c# statement?

edit: extra thanks if someone can provide 开发者_开发知识库some documentation/reference for the vbscript behavior.


Since in C# a string can also be NULL, I would use the following:

if(!string.IsNullOrEmpty(sCode))
    //do something


I'm not a vbscript expert, but my hunch is vbscript overloaded > with strings to compare them ordinally. So if that is the case, then in C# sCode.CompareTo(string.Empty) will give you what you need, -1 if sCode less than the empty string (which is not possible in this case), 0 if they are equal, and 1 if sCode comes after.

In this particular case you can just check if sCode is the empty string though.


I would just simply do !=, which appears to be the intent of the code:

if(sCode != String.Empty)
  Do();


In your particular case you simply compare to 'string.Empty' but the more generic answer is that it's (usually) a case insensitive alphanumeric comparison. E.g "ababa" < "z1asdf" is true. To represent that in C# you could do:

'string.Compare(A,B) < 0' which is equivallent of 'A

(usually) because it can be specified


Use the "<>" (not equal to) operator, like so:

dim string
string = "hello"
if (string <> "") then
    WScript.Echo "We're Ok" & VbCrLf
else
    WScript.Echo "Empty String" & VbCrLf
End if
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜