Try this in 3.5.0.24
Quotevoid game_start()
{
String s = "a";
if (s.Contains(" ")) {
AbortGame("Wut?");
}
}
Strings are not even supposed to have a function "Contains".
I've tried to overload the function with my own extender, but the compiler says :
QuoteString.Contains already exists
I confirm, this function is declared in String and exists in the engine at least since AGS 3.2.1.
Quote
import int Contains(const string needle); // $AUTOCOMPLETEIGNORE$
but it's marked with AUTOCOMPLETEIGNORE so does not show up in autocomplete.
Also, judging by the above test result, it's not working correctly. Maybe it was introduced by CJ at some point, but never finished, and forgotten.
EDIT: actually, it's not bool, it returns -1 if it fails, and >=0 for the index of the found substring.
Also, it's case-insensitive.
According to the manual it's an old (deprecated) function, superseded by String.IndexOf(). Sounds like it actually functions identically to IndexOfâ€"maybe it was just renamed to better describe its functioning.
Quote from: Snarky on Sun 01/11/2020 23:33:57
According to the manual it's an old (deprecated) function, superseded by String.IndexOf(). Sounds like it actually functions identically to IndexOfâ€"maybe it was just renamed to better describe its functioning.
Yes, that would explain. And IndexOf function is an alias to same implementation in the engine.
From Changes.txt:
Quote
VERSION 3.1, October 2008
<...>
- Renamed String.Contains to String.IndexOf to reduce confusion with other
languages such as Java and C#. String.Contains will continue to work as well for
the foreseeable future
In regards to all of the above, either this function is meant to have a life of its own and be changed to returning a bool, or it's exactly redundant to IndexOf and it should be deleted entirely.
In the backward-compatible version of the engine it may be hidden behind the script api check, as we do to deprecated functions now, as in theory it could've been used in early 3.* games.
It may be easily deleted in versions that allow breaking changes.
OK! Good enough for me. I didn't mean to be pedantic. Thanks for answering!