zoukankan
html css js c++ java
按不同国家语言进行字符串排序
void
Page_Load(
object
sender, EventArgs e)
{
//
测试数据
string
[] myArr
=
new
string
[
6
];
myArr[
0
]
=
"
地域
"
;
myArr[
1
]
=
"
地図
"
;
myArr[
2
]
=
"
路線
"
;
myArr[
3
]
=
"
道路交通
"
;
myArr[
4
]
=
"
電話帳
"
;
myArr[
5
]
=
"
自動車
"
;
//
没有排序
Gridview1.DataSource
=
myArr;
Gridview1.DataBind();
//
简体中文排序
MyStringComparer myComp
=
new
MyStringComparer(CompareInfo.GetCompareInfo(
"
zh-CN
"
), CompareOptions.None);
Array.Sort(myArr, myComp);
Gridview2.DataSource
=
myArr;
Gridview2.DataBind();
//
日语排序
myComp
=
new
MyStringComparer(CompareInfo.GetCompareInfo(
"
ja-JP
"
), CompareOptions.None);
Array.Sort(myArr, myComp);
Gridview3.DataSource
=
myArr;
Gridview3.DataBind();
}
private
class
MyStringComparer : IComparer
{
private
CompareInfo myComp;
private
CompareOptions myOptions
=
CompareOptions.None;
//
Constructs a comparer using the specified CompareOptions.
public
MyStringComparer(CompareInfo cmpi, CompareOptions options)
{
myComp
=
cmpi;
this
.myOptions
=
options;
}
//
Compares strings with the CompareOptions specified in the constructor.
public
int
Compare(Object a, Object b)
{
if
(a
==
b)
return
0
;
if
(a
==
null
)
return
-
1
;
if
(b
==
null
)
return
1
;
string
sa
=
a.ToString();
string
sb
=
b.ToString();
if
(sa
!=
null
&&
sb
!=
null
)
return
myComp.Compare(sa, sb, myOptions);
throw
new
ArgumentException(
"
a and b should be strings.
"
);
}
}
查看全文
相关阅读:
The type or namespace name 'Windows' does not exist in the namespace....
WCF 事件处理
ASP.Net程序在IIS7的部署问题
Oracle Package的全局变量与Session
[ASP.NET]C1Webgrid中实现编辑和计算
EXCEL妙用:选取单元格时改变整行的背景色
[转]22 个精美的网站管理后台模板推荐
[转]C#开发Active控件(二)
Oracle获取时间差的技巧
C#里的Random
原文地址:https://www.cnblogs.com/goodspeed/p/62715.html
最新文章
PureFtpd 1.0.21 + OpenLDAP 2.3.20 安装
修复 ASP.NET
Maven2 & Continuum 持续整合 (2)
Subversion 1.4.3 + Apache 2.2.4 for Linux 安装
MySQL 5.0 存储过程 (2) 事务 & SQLEXCEPTION
How to add “Maven Managed Dependencies” library in build path eclipse?
#干货向#浅析http协议、cookies和session机制、浏览器缓存
深入理解HTTP协议
[译]JavaScript:打破所有规则
Web 前端开发者必知的9 个 CSS 属性
热门文章
在javascript代码中取得当前代码所在的script元素对象
怎样用好Google进行搜索
12个有趣的C语言面试题
10个超棒jQuery表单操作代码片段
JavaScript中有趣的反柯里化
#干货向#如何写robots.txt?
问题排查不要忽略基础性东西的检测
从索引X处开始,初始化字符串的格式不符合规范
搜集新书
XtraGrid动态加载多表头
Copyright © 2011-2022 走看看