GetMaximumAppendedNumber
(
ListObject oTable,
String sColumnNameBase
)
{
Debug.Assert(oTable != null);
Debug.Assert( !String.IsNullOrEmpty(sColumnNameBase) );
AssertValid();
Int32 iMaximumAppendedNumber = 0;
Regex oRegex = GetColumnNameRegex(sColumnNameBase);
foreach (ListColumn oColumn in oTable.ListColumns)
{
String sColumnName = oColumn.Name;
Int32 iAppendedNumber = -1;
if ( String.IsNullOrEmpty(sColumnName) )
{
continue;
}
// Look for an exact match.
if (sColumnName == sColumnNameBase)
{
iAppendedNumber = 1;
}
else
{
// Look for a "starts with" match.
Match oMatch = oRegex.Match(sColumnName);
if (
!oMatch.Success
||
!Int32.TryParse(
oMatch.Groups[AppendedNumberGroupName].Value,
out iAppendedNumber)
)
{
continue;
}
}
Debug.Assert(iAppendedNumber != -1);
iMaximumAppendedNumber =
Math.Max(iAppendedNumber, iMaximumAppendedNumber);
}
return (iMaximumAppendedNumber);
}