[IronPython] In fix for strings

Brian Quinlan brian at sweetapp.com
Sun Oct 10 04:52:08 PDT 2004

IronPython 0.6.0 doesn't support the "in" operator correctly for string
types. To demonstrate:

>>> 'abc' in 'abcd'

Here is my fix (sorry for the lack of a diff - I don't have access to
the original source right now).

Add to StringOps class:

public static bool Contains(string s, object o) {
	if (o is string)
		return s.IndexOf((string) o) != -1;
		throw Ops.TypeError("requires string as left operand");

Add to Ops.In:

public static object In(object x, object y) {
	if (y is string) {
		return bool2object(StringOps.Contains((string) y, x));
	} else if (y is IDictionary) {


More information about the users-ironpython.com mailing list