public class MyComparer : System.Collections.IComparer { public MyComparer() {
}
#region IComparer メンバ
public int Compare(object x, object y) { string a = (string)x; string b = (string)y;
//正規表現で末尾の数字を取得 System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("(?<num>\\d*)$"); int numA = int.Parse(regex.Match(a).Groups["num"].Value); int numB = int.Parse(regex.Match(b).Groups["num"].Value);
return numA - numB; }
#endregion }
という風にIComparerの実装を作っておいて
string[] ary = new string[] { "ABC012", "ZZ101", "Z99", "A23", "B11" }; Array.Sort(ary, new MyComparer());
with Ada.Numerics.Discrete_Random,Ada.Text_Io,Ada.Integer_Text_Io,Ada.Calendar; use Ada.Text_Io,Ada.Integer_Text_Io,Ada.Calendar; procedure game Is package R Is New Ada.Numerics.Discrete_Random(natural); use R; type Four_Array is array(1..4)of Integer; function Generate Return Integer is seed:Generator; begin Reset(seed,Integer(Seconds(Clock)*100)); return Random(Seed) mod 10; end Generate; function Search(Target:Four_array;Seed:In Integer) Return integer Is begin for I in 1..4 loop if Target(I) = Seed then return i; end if; end loop; return 0; end Search; procedure Initialize(computer:In out Four_array) is begin for I in 1..4 loop computer(I):=-1; end loop; end initialize;