Hi Marc,
No! I was probably not explaining myself clear enough.
XXX was just an example. Actually, the highest revision level is ZZZ for
mechanical engineering CAD drawings and 999 for architectural engineering
CAD drawings. Now you may ask
why would the last revision level be ZZZ
or 999? My response is it's a company standard.
Our CAD drawings have a placeholder for a maximum of three revision levels.
When a new mechanical engineering CAD drawing is created it's revision level
is "A". When a change is made, to this type of CAD drawing, the revision
level is incremented to the next letter. This process is repeated for each
engineering change.
Since I stated there's a placeholder for a maximum of three revision levels,
revision "D" would replace the revision "A", revision "E" would replace
revision "B" and revision "F" would replace revision "C", etc., etc., etc.
When the last revision is "Z", the next revision would be "AA" followed by
"AB", "AC", "AD", ...,"AZ", "BA", "BB", ...,"BZ", ...,"ZA", ..., "ZZ",
"AAA", ...,"AAZ", etc., etc., etc. So, theoretically a mechanical
engineering CAD drawing could have 17,576 revisions. Will there ever be that
many revision levels? NO WAY!
I hope the above wasn't to much babble!
Yes, Yes, Yes
I haven't tested your code with numbers, but I have tested
it with letters. Here's an example. Your code will sort the following string
array:
Z
AA
AB
Like this:
AA
AB
Z
I needed it to be sorted like:
Z
AA
AB
After studying your code and other responses, here's what I came up with:
public class sortRevision : IComparer
{
int IComparer.Compare(Object x, Object y)
{
int val = ((new CaseInsensitiveComparer()).Compare(x, y));
string localx = (string)x;
string localy = (string)y;
if (val < 0)
{
if (localx.Length > localy.Length)
val = 1;
}
if (val > 0)
{
if (localx.Length < localy.Length)
val = -1;
}
return val;
}
}
I am calling the above as follows:
Array.Sort(allRevLevels, (IComparer)new sortRevision());
Any suggestions are welcome and greatly appreciated!
Thanks!