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.
"
);
}
}
查看全文
相关阅读:
springboot和springcloud版本对应关系
nexus安装包下载
centos7安装Redis的踩坑之旅
搭建本地Spring Initializr服务器
ElasticSearch数据查看插件elasticsearch-head
ELK学习历程
如何使用ob函数输出静态html文件
微信开发之获取jsapi_ticket
static_关键字
static关键字_1
原文地址:https://www.cnblogs.com/goodspeed/p/62715.html
最新文章
python2与python3的不同
python直接赋值、浅拷贝、深拷贝的区别
python的imread、newaxis
解释性和编程性语言
requests乱码问题
巡风的扫描与漏斗检测脚本分析
童话故事 --- 类模板与函数模板的实例化
再论C++引用(reference)类型
学习积累
获取Windows系统中的串口
热门文章
童话故事 --- CPU的贴身侍卫ITCM和ICache
童话故事 --- 蓝牙通信 --- 连接手机和嵌入式设备
童话故事 --- 通信协议之 HDLC 浅析
童话故事 --- 什么是SQL Server Browser
深入浅出谈4G ─ 4G LTE网速到底有多快?
深入浅出C++引用(Reference)类型
mysql各种版本下载
Springboot跨域问题
outlook 您的组织策略阻止我们为您完成此操作 解决办法
centos7安装GCC
Copyright © 2011-2022 走看看