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.
"
);
}
}
查看全文
相关阅读:
GNU make查找makefile的顺序
解决ssh登录过慢的问题
大小端转换定义结构体的技巧
git解决git apply时遇到trailing whitespace问题
Qualcomm Atheros AR9485 无线网卡驱动问题
tcpdump入门笔记
Linux内核探索之路——关于书
Ubuntu下最好用的词典Golden Dict设置支持有道
ubuntu14.04完美安装并设置搜狗输入法
ubuntu网络已禁用的解决方案
原文地址:https://www.cnblogs.com/goodspeed/p/62715.html
最新文章
Layui表格导出功能兼容IE
js 金额格式化-千位分隔符
js 当前日期格式化 YYYY-MM-DD
git 查看不到新分支
git显示untracked files(未监控)解决办法
React-Native中Navigator浅析
git 部分文件提交
React中Connect原理
http1.0、http1.1、http2.0区别
React渲染过程
热门文章
进程与线程
Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
Cannot resolve com.oracle:ojdbc6:11.2.0.1.0 解决方案
Java集合
Java泛型
Java反射
代理模式
命令模式
final关键字
Java技能图谱
Copyright © 2011-2022 走看看