private static object Substr(IContext context, object @this, object[] arguments)
{
string str = (string)@this;
int from = 0;
int? length = null;
if (arguments.Length > 0)
try
{
from = Convert.ToInt32(arguments[0]);
}
catch
{
}
if (arguments.Length > 1)
try
{
length = Convert.ToInt32(arguments[1]);
}
catch
{
}
if (from >= str.Length)
return string.Empty;
if (from < 0)
{
from = str.Length + from;
if (from < 0)
from = 0;
}
if (length.HasValue)
{
if (length.Value <= 0)
return string.Empty;
return str.Substring(from, length.Value);
}
return str.Substring(from);
}