字典里血102000大写怎么写写

iOS简单排序--字母排序、NSDictionary排序
数组用系统方法compare做字母的简单排序
&&NSArray *oldArray = @[@"bac",@"bzd",@"azc",@"azz"];
&&NSArray *newArray = [oldArray sortedArrayUsingSelector:@selector(compare:)];
& NSLog(@"new array = %@",newArray);
因为NSDictionary排序
& NSMutableDictionary *dict = [[NSMutableDictionary alloc]
& & [dict setObject:@"1" forKey:@"key1"];
& & [dict setObject:@"2" forKey:@"key2"];
& & [dict setObject:@"3" forKey:@"key3"];
& & [dict setObject:@"4" forKey:@"key4"];
& & for (NSString *str in [dict allKeys]) {
& NSLog(@"key ==
& & NSArray *keys = [dict allKeys];
& & NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
& & return [obj1 compare:obj2 options:NSNumericSearch];
& & for (NSString *categoryId in sortedArray) {
& & NSLog(@"[dict objectForKey:categoryId] ===
%@",[dict objectForKey:categoryId]);
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
2. 使用CollectionsUtil类(在System.Collections.Specialized命名空间内)
Hashtable hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable();
不可以指定CultureInfo
只支持Hashtable和SortedList
用于非泛型类,在.NET Framework 2.0后使用没有多大意义
在.NET Framework 2.0后有的方法
3. 使用StringComparer类
利用构造函数
public Hashtable(IEqualityComparer equalityComparer);
使用2.0后的StringComparer类(StringComparer类继承了很多组建接口,包括非泛型)
public abstract class StringComparer :
&&& IComparer,
&&& IEqualityComparer,
&&& IComparer&string&,
&&& IEqualityComparer&string&
Hashtable hashtable = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
可以指定CultureInfo,推荐
泛型类:Dictionary
直接使用StringComparer类
利用构造函数
public Dictionary(IEqualityComparer&TKey& comparer);
使用2.0后的StringComparer类(StringComparer类继承了很多组建接口,包括非泛型)
public abstract class StringComparer :
&&& IComparer,
&&& IEqualityComparer,
&&& IComparer&string&,
&&& IEqualityComparer&string&
Dictionary&string, object& dic = new Dictionary&string, object&(StringComparer.CurrentCultureIgnoreCase);
可以指定CultureInfo,推荐
SortedList类
使用CaseInsensitiveComparer,因为他继承IComparer
使用StringComparer类,他继承IComparer&string&
SortedList slist = new SortedList(CaseInsensitiveComparer.Default);
SortedList&string, object& slistGeneric =
&&& new SortedList&string, object&(StringComparer.CurrentCultureIgnoreCase);
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'中各种创建不区分大小写字典的方法',
blogAbstract:'/mgen//zh-cn/library/system.collections.specialized.collectionsutil.aspx\n\t\n\t\t\n\t\t\t非泛型类:Hashtable \n\n从.NET Framework 1.0就有的方法\n\n1. 直接构建Hashtable类\n\n\n
利用的构造函数:\n\n
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:3,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}“军人字典里大写着服从”
“军人字典里大写着服从”
生活之所见
夏日,天微微亮,第78集团军某合成旅信息保障队工程师左艳辉全副武装,跟随梯队官兵来到车站时,她的丈夫陈涛抱着孩子已等候许久。“妈妈什么时候回……回来。”此时,儿子已哭成“泪人”,见到妈妈便踉踉跄跄迈着小步跑过去。左艳辉一把抱住孩子,泪水也在眼角打转转。单位改革调整后不久,又接到移防的命令。一开始她有些不知所措:双方父母都在各自老家,身体都不好;孩子还很小,丈夫年初刚刚转业到驻地……左艳辉知道,这是家人最需要她的时候。那天晚上,她特意做了一桌丰盛的晚餐。吃饭时,她把移防的消息告诉了丈夫。两人沉默许久,左艳辉刚准备向丈夫解释,丈夫起身走到她身前,拍着她的肩膀说:“我都明白,别忘了我也曾是一名军人。”准备移防期间,家里又接连发生意外,孩子因为疝气做了手术,左艳辉的公公被查出癌症晚期。公公对她说:“我这辈子最自豪的事情,就是儿子儿媳都有从军的经历。家里的事你不要担心!”一句话胜过千言万语。“军人字典里大写着服从”……站台上,送行的家人们千叮咛万嘱咐,泪水与不舍绘出一道告别的风景。终于,部队收到登车命令。此刻,儿子把左艳辉的脖子搂得更紧,哭着不愿离开。丈夫用力掰开小手抱走小家伙,左艳辉抹着眼角跟随梯队上车。列车鸣笛离开,加速、加速。左艳辉收到丈夫发来的消息:千里万里,我们心手相牵。
本文仅代表作者观点,不代表百度立场。系作者授权百家号发表,未经许可不得转载。
生活之所见
百家号 最近更新:
简介: 以我之言,记录这个时代的普通人的心灵世界
作者最新文章iOS字典的排序问题 - 简书
iOS字典的排序问题
在日常开发中,经常会遇到根据字典的Key对Value进行排序的问题,所以对于此类问题抽出一个通用方法,废话不多说,上代码.
对字典(Key-Value)排序 区分大小写
@param dict 要排序的字典
- (void)sortedDictionary:(NSDictionary *)dict{
//将所有的key放进数组
NSArray *allKeyArray = [dict allKeys];
//序列化器对数组进行排序的block 返回值为排序后的数组
NSArray *afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id
_Nonnull obj1, id
Nonnull obj2) {
In the compare: methods, the range argument specifies the
subrange, rather than the whole, of the receiver to use in the
comparison. The range is not applied to the search string.
example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
compares "A" to "ABC", not "A" to "A", and will return
NSOrderedAscending. It is an error to specify a range that is
outside of the receiver's bounds, and an exception may be raised.
- (NSComparisonResult)compare:(NSString *)
compare方法的比较原理为,依次比较当前字符串的第一个字母:
如果不同,按照输出排序结果
如果相同,依次比较当前字符串的下一个字母(这里是第二个)
NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
注意:compare方法是区分大小写的,即按照ASCII排序
//排序操作
NSComparisonResult resuest = [obj1 compare:obj2];
NSLog(@"afterSortKeyArray:%@",afterSortKeyArray);
//通过排列的key值获取value
NSMutableArray *valueArray = [NSMutableArray array];
for (NSString *sortsing in afterSortKeyArray) {
NSString *valueString = [dict objectForKey:sortsing];
[valueArray addObject:valueString];
NSLog(@"valueArray:%@",valueArray);
代码中提到了排序是按照ASCII码排序,因为ASCII码表示区分大小写的,所以我们的排序结果也区分大小写.
ASCII表.jpg
如果不想区分大小写,可以在比较前,可以用lowercaseString方法将字符串转换为小写.代码如下
对字典(Key-Value)排序 不区分大小写
@param dict 要排序的字典
- (void)sortedDictionarybyLowercaseString:(NSDictionary *)dict{
//将所有的key放进数组
NSArray *allKeyArray = [dict allKeys];
//序列化器对数组进行排序的block 返回值为排序后的数组
NSArray *afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id
_Nonnull obj1, id
Nonnull obj2) {
In the compare: methods, the range argument specifies the
subrange, rather than the whole, of the receiver to use in the
comparison. The range is not applied to the search string.
example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
compares "A" to "ABC", not "A" to "A", and will return
NSOrderedAscending. It is an error to specify a range that is
outside of the receiver's bounds, and an exception may be raised.
- (NSComparisonResult)compare:(NSString *)
compare方法的比较原理为,依次比较当前字符串的第一个字母:
如果不同,按照输出排序结果
如果相同,依次比较当前字符串的下一个字母(这里是第二个)
NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
注意:compare方法是区分大小写的,即按照ASCII排序
//小写转化
obj1 = [obj1 lowercaseString];
obj2 = [obj2 lowercaseString];
//排序操作
NSComparisonResult resuest = [obj1 compare:obj2];
NSLog(@"afterSortKeyArray:%@",afterSortKeyArray);
//通过排列的key值获取value
NSMutableArray *valueArray = [NSMutableArray array];
for (NSString *sortsing in afterSortKeyArray) {
NSString *valueString = [dict objectForKey:sortsing];
[valueArray addObject:valueString];
NSLog(@"valueArray:%@",valueArray);
简单测试代码
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"Danny",@"Basd",@"12",@"Cerff",@"man",@"ABCDEFG",@"Sean",@"Cerf",nil];
NSLog(@"dictionary:%@",dict);
[self sortedDictionary:dict];
11:23:03.484 根据key对dictionary排序[] dictionary:{
ABCDEFG = 12345;
11:23:03.484 根据key对dictionary排序[] afterSortKeyArray:(
11:23:03.485 根据key对dictionary排序[] valueArray:(
代码此时例子较多,就不都放上来了,大家可放心食用.}

我要回帖

更多关于 壹到拾大写怎么写 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信