[Thread Prev][Thread Next][Index]

Re: How to compare a string?



On Tue, 21 Oct 2003, Chi Ding wrote:
>     I need to compare a string variable and then accordingly continue my
> code. Here is my code in a file named test.jnl
>
> let a=strcmp($1,"yes")
> if `a eq 0` then
> endif
>
>      I also tried the statement
> if `$1 eq yes`,  but it didn't work either.

Hi Ding,

For your first example, try this instead:

   let a=strcmp("($1)","yes")

For your second example, try

   if `"($1)" eq "yes"` then

The quotes "" indicate that "($1)" and "yes" should be interpreted as strings,
not as variables.  The parentheses () around the $1 prevent Ferret from
interpreting the trailing quote as the start of a "default string", as in:

http://ferret.wrc.noaa.gov/Ferret/Documentation/Users_Guide/current/Chapter1_Introduction.htm#_VPINDEXENTRY_97

Cheers,

Andrew

+--------------------------------------------------------+
|   Dr. Andrew T. Wittenberg   |        GFDL/NOAA        |
|  Andrew.Wittenberg@noaa.gov  |      Princeton, NJ      |
+--------------------------------------------------------+




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement