views:

45

answers:

5

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.

+1  A: 

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

if(!string.IsNullOrEmpty(sCode))
    //do something
RedFilter
A: 

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

if(sCode != String.Empty)
  Do();
Corey Coogan
+1  A: 

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.

Matt Greer
since the original code was checking against an empty string, the c# check can be reduced to RedFilter's example. if it were non-empty then i think `CompareTo` would be appropriate, so +1.
lincolnk
A: 
Rune FS
A: 

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
gWaldo