0

When statement question

So I might be trying to do something when just isn't built to handle. I'm doing a check against a substring, well call S, that can be 1 to 3 characters long. In the case of 3 characters I just want to know that all characters are there. I want my leftside to say something like if('a' in S && 'b' in S && 'c' in S) -> ... but that didn't work. I ended up writing 8 different expressions to show each combo of those 3 char possible but I don't like how it looks.

27th Mar 2023, 3:28 PM
Bob
2 Answers
+ 5
Based on your problem statement, you might solve this with set operations. val S = "cba" print("abc".toSet() == S.toSet()) Link to your code, maybe we can analyze further.
27th Mar 2023, 3:39 PM
Tibor Santa
Tibor Santa - avatar
+ 1
I would, but I have no luck with the website, and the files are on my pc. I think using sets might help. I'm a little disappointed that I didn't think of it myself. There is a subsection where order matters, but I figured that one out. My solution to that one fell into the not elegant enough to brag, but it's readable works and looks good enough that I can move on
27th Mar 2023, 4:07 PM
Bob