public static String getInfoString(String source, String key, String defaultValue)
{
if (String.IsNullOrEmpty(source)) {
return defaultValue;
}
key = "#"+ key;
int i = source.ToLower().IndexOf(key.ToLower(), 0);
// the key can't apears more than one
//
if (source.ToLower().IndexOf(key.ToLower(), i + 1) != -1)
{
throw(new Exception("cUtil.getInfoString: the key can't apears more than one."));
}
// if the key is not present return default
//
if (i == -1)
{
return defaultValue;
}
else
{
const string c_errorstr = "cUtil.getInfoString: source invalid, the character {0} is not present.";
int j = source.ToLower().IndexOf(";".ToLower(), i);
if (j == -1)
{
throw(new Exception(String.Format(c_errorstr, ";")));
}
int k = source.Substring(i, j-i).ToLower().IndexOf("=".ToLower(), 0);
if (k == -1)
{
throw(new Exception(String.Format(c_errorstr, "=")));
}
k = k + i;
return source.Substring(k + 1, j - k - 1);
}
}