public string GetUrlAtCharacterIndex (int characterIndex)
{
string s = printedText;
if (characterIndex != -1 && characterIndex < s.Length - 6)
{
int linkStart;
// LastIndexOf() fails if the string happens to begin with the expected text
if (s[characterIndex] == '[' &&
s[characterIndex + 1] == 'u' &&
s[characterIndex + 2] == 'r' &&
s[characterIndex + 3] == 'l' &&
s[characterIndex + 4] == '=')
{
linkStart = characterIndex;
}
//Awlays return -1 here.
//String.LastIndexOf(string value, int startIndex),then second param means "endIndex", not “startIndex”.
//Maybe its a C# problem
else linkStart = s.LastIndexOf("[url=", characterIndex);
if (linkStart == -1) return null;
...
}
return null;
}