In order to omit the space and make it visible to the operator who manually fills in the paper, the volume number on the card of the materials shelf is determined to be classified and sorted, as shown in
A-3, A-4, A-5, A-8 forming A-3 ~ 5, 8, etc.
The following code uses a few auxiliary list <int>:
/// <Summary>
/// Similar to 1, 2, 3, 5, 7, 8, 10, 11, 12, 13, 14, 15, 16, 21, 22, convert to 1 ~ 3, 5, 7 ~ 8, 10 ~ 16,21 ~ 22
/// </Summary>
/// <Param name = "strinput"> input string, for example, 1, 2, 3, 5, 7, 8, 10, 11, 12, 13, 14, 15, 16, 21, 22 </param>
/// <Returns> the new string, for example, 1 ~ 3, 5, 7 ~ 8, 10 ~ 16,21 ~ 22 </returns>
Private string makesimplestring (string strinput)
{
String stroutput = "";
// Put the integer in Il
String [] Ss = strinput. Split (',');
List <int> IL = new list <int> ();
For (INT I = 0; I <ss. length; ++ I)
{
Try
{
Int K = convert. toint32 (ss [I]);
Il. Add (k );
}
Catch
{
If (stroutput = "")
Stroutput = ss [I];
Else
Stroutput + = "," + SS [I];
}
}
If (IL. Count> 0)
{
// Place the continuous numbers in IL into different lists <int>.
Il. Sort ();
List <list <int> ill = new list <int> ();
Int Prev = il [0];
List <int> ltemp = new list <int> ();
Ltemp. Add (prev );
Ill. Add (ltemp );
For (INT I = 1; I <Il. Count; ++ I)
{
If (IL [I]-Prev = 1)
{
Ill [ill. Count-1]. Add (IL [I]);
}
Else
{
Ltemp = new list <int> ();
Ltemp. Add (IL [I]);
Ill. Add (ltemp );
}
Prev = il [I];
}
// Generate the result string
For (INT I = 0; I <ill. Count; ++ I)
{
If (ill [I]. Count = 1)
{
If (stroutput = "")
Stroutput = ill [I] [0]. tostring ();
Else
Stroutput + = "," + ill [I] [0]. tostring ();
}
Else
{
If (stroutput = "")
Stroutput = ill [I] [0]. tostring () + "~ "+ Ill [I] [ill [I]. Count-1]. tostring ();
Else
Stroutput + = "," + ill [I] [0]. tostring () + "~ "+ Ill [I] [ill [I]. Count-1]. tostring ();
}
}
}
Return stroutput;
}