您的位置:首页 > 编程语言 > C#

C#对字符串进行排序 支持中文 笔画和拼音

2016-12-20 13:14 2021 查看
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;

namespace cn.ava.PublicsUtil.Util
{
public class SortUtil
{
/// <summary>
/// 排序
/// </summary>
/// <param name="arr">排序字符串数组</param>
/// <param name="type">类型:1发音,2笔画</param>
/// <returns></returns>
public static string[] SortArray(string[] arr, int? type = 1)
{
//发音 LCID:0x00000804
if (type.Value == 1)
{
CultureInfo PronoCi = new CultureInfo(2052);
Array.Sort(arr);
}
else
{
//笔画数 LCID:0x00020804
CultureInfo StrokCi = new CultureInfo(133124);
Thread.CurrentThread.CurrentCulture = StrokCi;
Array.Sort(arr);
}
return arr;
}
/// <summary>
/// 排序
/// </summary>
/// <param name="arrlist">排序字符串数组</param>
/// <param name="type">类型:1发音,2笔画</param>
/// <returns></returns>
public static List<string> SortList(List<string> arrlist, int? type = 1)
{
string[] arr = arrlist.ToArray();
//发音 LCID:0x00000804
if (type.Value == 1)
{
CultureInfo PronoCi = new CultureInfo(2052);
Array.Sort(arr);
}
else
{
//笔画数 LCID:0x00020804
CultureInfo StrokCi = new CultureInfo(133124);
Thread.CurrentThread.CurrentCulture = StrokCi;
Array.Sort(arr);
}
return arr.ToList<string>();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息