-
Notifications
You must be signed in to change notification settings - Fork 13.4k
How can I compare string..? #3463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think we can't compare the words which are static or constants. That's the problem why I can't compare :) |
You probably need to compare against ~"unique strings" |
You can use == to compare strings, and as jdm says, you need the tilde in front of the strings if item == ~"salad" {
price = 3.5;
} else if item == ~"kiwie" {
price = 2.25;
} else {
price = 5.0;
} Should make it compile, although I'm working off of the Master branch rather than the 0.3 release (and in mine, I have to cast the result of io::stdin() to io::ReaderUtil to get at read_line() |
We're working on a number of bugs in this space; you're sort of stumbling over them all at once, sadly. We hope this will be cleaned up soon. It should not generally be necessary; in the meantime, |
I don't understand what the... bug is here, exactly? Is this a dup of #3470? |
No clear bug, far as I know things are working, closing. |
For posterity's sake: the reason that we can't just implement equality for |
1 import io::;
2 import core::;
3 fn main(){
4 let price;
5
6 let item = io::stdin().read_line();
7
8 if str::eq(item,"salad"){
9 price = 3.5;
10 }else if str::eq(item,"kiwie"){
11 price = 2.25;
12 }else{
13 price = 5.0;
14 }
15
16 io::println(#fmt("%f",price));
17 }
I used to develope with C but there is a function "strcmp" but here. I don't know which I can use comparing the string..
Let me know them how to use.
Also I'd like to know about how to use API document properly. I can find and see the function and some kind of that. But I don't know how to use exactly
The text was updated successfully, but these errors were encountered: