[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Switch statement
From: |
Ben Abbott |
Subject: |
Re: Switch statement |
Date: |
Sun, 16 Oct 2011 10:43:25 -0400 |
On Oct 16, 2011, at 4:21 AM, Roy Menachem wrote:
> Hi,
> For some reason when I use switch case statement by comparing strings, it
> doesn’t work.
> Any idea why? Is there any known problem with a string?
> Example:
> i=1;
> while(i<=parameters_length)
> switch (txt_data(i,19)) ##txt_data is array of strings
>
> case 'T1_ps'
> T1=num_data(i,9);
>
> case 'T2_ps'
> T2=num_data(i,9);
> case 'Min_data'
> min_data=num_data(i,9);
> otherwise
> printf("no value\n");
> endswitch
> i++;
> endwhile
>
>
> Thanks,
>
> Roy
I think the problem is with ...
> switch (txt_data(i,19))
txt_data(i,19) returns the 19th character from the ith row of the array. You
then compare a single character string with strings that are 5 or 6 characters
long.
I think you want ...
> switch (strtrim (txt_data(i,1:end)) )
Ben