How to compare strings?
I'm trying to check strings for equality but the following doesn't work "abc" => string s; if(s=="abc"){<<<"yes">>>;} -mb
Hi, Right now string operations are quite limited. You can't cast strings, as mentioned in an earlier post, and you can't concatenate strings. Right now strings are stored as object references. You can make this work: if (s==s)<<<"yes">>>; But that isn't very useful. String operations have become a popular item in demand and I think it is on the queue for development. I know this isn't a satisfactory answer but most of the dev team is in Europe for ICMC and I thought I would try to give you an answer in the interim. --art On Sep 3, 2005, at 1:26 AM, Manfred Brockhaus wrote:
I'm trying to check strings for equality but the following doesn't work
"abc" => string s; if(s=="abc"){<<<"yes">>>;}
-mb
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Thanks for the clarification. No big problem actually. I'm quite confident that the brilliant team will complete the language as soon as possible. -mb On Sep 3, 2005, at 7:49 PM, Adam R. Tindale wrote:
Hi,
Right now string operations are quite limited. You can't cast strings, as mentioned in an earlier post, and you can't concatenate strings. Right now strings are stored as object references. You can make this work:
if (s==s)<<<"yes">>>;
But that isn't very useful.
String operations have become a popular item in demand and I think it is on the queue for development.
I know this isn't a satisfactory answer but most of the dev team is in Europe for ICMC and I thought I would try to give you an answer in the interim.
--art
On Sep 3, 2005, at 1:26 AM, Manfred Brockhaus wrote:
I'm trying to check strings for equality but the following doesn't work
"abc" => string s; if(s=="abc"){<<<"yes">>>;}
-mb
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
I figured out that 'associative arrays' can be used for string comparison, ie. by associating unique numbers with the strings to be checked. For example int x[0]; 1 => x["abc"]; 2 => x["def"]; ... Now a string variable s can be checked for equality by writing if(x[s]==x["abc"])... Note that this works without explicit use of the numbers. -mb On Sep 3, 2005, at 8:46 PM, Manfred Brockhaus wrote:
Thanks for the clarification. No big problem actually. I'm quite confident that the brilliant team will complete the language as soon as possible.
-mb
On Sep 3, 2005, at 7:49 PM, Adam R. Tindale wrote:
Hi,
Right now string operations are quite limited. You can't cast strings, as mentioned in an earlier post, and you can't concatenate strings. Right now strings are stored as object references. You can make this work:
if (s==s)<<<"yes">>>;
But that isn't very useful.
String operations have become a popular item in demand and I think it is on the queue for development.
I know this isn't a satisfactory answer but most of the dev team is in Europe for ICMC and I thought I would try to give you an answer in the interim.
--art
On Sep 3, 2005, at 1:26 AM, Manfred Brockhaus wrote:
I'm trying to check strings for equality but the following doesn't work
"abc" => string s; if(s=="abc"){<<<"yes">>>;}
-mb
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Greetings Manfred,
I figured out that 'associative arrays' can be used for string comparison, ie. by associating unique numbers with the strings to be checked. For example
int x[0]; 1 => x["abc"]; 2 => x["def"]; ...
Now a string variable s can be checked for equality by writing
if(x[s]==x["abc"])...
Note that this works without explicit use of the numbers.
We hereby present you with the award for "best work-around of the month necessitated by a bug in ChucK". This hack is simply fantastic (especially since strings are quite broken in the language). Thanks for pointing out the string comparison bug (now on the 1.2.0.1 queue) and this rather unforeseen use of associative arrays. Best, Ge!
participants (3)
-
Adam R. Tindale
-
Ge Wang
-
Manfred Brockhaus