Substring Exception

I’m having an issue using Substring, whenever my search input exceeds 5 characters, I keep getting the following Exception:

ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
System.String.Substring (Int32 startIndex, Int32 length)
MyScript.OnGUI () (at Assets/MyScript.cs:757)

Here’s what I’m using to call it, anyone got some advice?

searchLength = mySearchStr.Length;

if(Regex.IsMatch(myArray*.name.Substring(0,searchLength), mySearchStr, RegexOptions.IgnoreCase))*

//Yada yada

I guess myArray*.name.Length is lower than searchLength. You can fix that with Mathf.Min( (…).name.Length, searchLength ), or other similar ways.*