排序含有数字的字符串:一个巧妙地方法
2014-09-29 17:15
309 查看
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] floors ={ "第3楼", "第2楼", "第11楼" }; Array.Sort<string>(floors, Factory.Comparer); foreach (string s in floors) Console.WriteLine(s); Console.ReadKey(); } } // 工厂模式 class Factory : IComparer<string> { private Factory() { } public static IComparer<string> Comparer { get { return new Factory(); } } public int Compare(string x, string y) { return x.Length == y.Length ? x.CompareTo(y) : x.Length - y.Length; } }
相关文章推荐
- 排序含有数字的字符串:一个巧妙地方法【转】
- 编写一个生成随机字符串的方法,参数接收长度,字符串中可能含有大写字母、 小写字母和数字。
- 一个字符串既含有字母又含有数字且字母和数字随意排列如何取出其中所有的数字并进行排序
- C#判断一个字符串是否是数字或者含有某个数字的方法
- 判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
- 判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
- 11.5 排序后的字符串数组,其中散布着空字符串,编写一个方法,找出给定字符串的位置。
- C++之String的find方法,查找一个字符串在另一个字符串的什么位置;leveldb字符串转数字解析办法
- 判断一个字符串是否为数字的方法总结
- 判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)--来源CSDN
- 判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
- 字符串类型的数字从小到大排序方法
- iOS中让一个数字字符串格式化(按照自己想要的格式输出)的方法
- 判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
- 如何排序含有数字的字符串
- 给一个整数数组,对数组中的每个整数中的所有数字按照升序排列(如101排序后为011)请写一个方法,输出排序后的数组中的最大数。 例如有一个数组: 101、132、375,排序后11、123、357,
- [shell]判断一个字符串是否为数字字符串的两种方法(是否为进程号(PID))
- 判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
- 判断一个字符串是否全是数字的多种方法及其性能比较
- 有什么最快的方法判断一个字符串内都是数字