Check if variable CONTAINS a specific character?

Is there a command in choicescript for checking whether a variable contains something?

For instance if I had a variable with a value of “abcdef”, is there a way to check whether the variable contains the character “b”?

*if var CONTAINS “b”.

I haven’t been able to find anything on the ChoiceScript Wiki or here on the forums so I thought I would just ask. Thanks!

I don’t think so.

I believe you could make a loop and check the string char by char, but I haven’t actually tried.

Cslib is a collection of pluggable, ready to use subroutines. In the cslib_string module you have three subroutines that could help you achieve what you want: find, index and contains. Contains being the one that best fit your use case.

4 Likes

Example:

*create mystr "abcef"
*gosub_scene cslib_string contains mystr "b"
*if cslib_ret
  Contains b!
3 Likes

Thank you! This is exactly what I was after - I will try it out and let you know how it goes.

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.