比较objective-C中的2个字符串 [英] Compare 2 strings in objective-C
本文介绍了比较objective-C中的2个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了以下代码:
if (depSelectedIndice > -1 && comSelectedIndice> -1)
{
NSLog(@"depart elemet : %d ",depSelectedIndice);
NSLog(@"depart elemet : %d ",comSelectedIndice);
NSLog(@"ok1");
NSString *choosedDate =[NSString stringWithFormat:@"%@%@",[deparatureDates objectAtIndex:depSelecif (depSelectedIndice > -1 && comSelectedIndice> -1)
{
NSLog(@"depart elemet : %d ",depSelectedIndice);
NSLog(@"depart elemet : %d ",comSelectedIndice);
NSLog(@"ok1");
NSString *choosedDate =[NSString stringWithFormat:@"%@%@",[deparatureDates objectAtIndex:depSelectedIndice], [goingBackDates objectAtIndex:comSelectedIndice]];
NSLog(@"0000000000001");
NSLog(@" number of element : %d", [allCombinations count]);
// for (int j=0; j<[allCombinations count]; j++)
// {
// NSLog(@"111111111111111111");
// // NSString *date = [[allCombinations objectAtIndex:j] objectForKey:@"keydate"];
// NSLog(@"22222222222222222222");
// if([date isEqualToString:choosedDate])
// {
// depPrice.text=@"1";
// comPrice.text=@"1";
// price.text=@"3";
//
// }
// }
}
$ b b
allCombinations是在.h中声明的NSArray,我有initilase并在另一个方法中使用它。我不能在这个方法中使用? :/
allCombinations is an NSArray declared in .h , I have initilase and use it in another method . I can't use in in this method ? :/
但我有一个crach。我真的不知道在哪里的问题,但我认为这是我比较if(date == choosedDate)?帮助请
But i have a crach . I don't really know where is the problem but i think it's when i compare if(date==choosedDate) ? Help please
推荐答案
当您在指针上使用 ==
code> NSString * 它是比较内存地址,不比较字符串的值。
When you use an ==
on pointers like NSString *
it is comparing memory addresses, not comparing the value of strings.
下面将实际比较字符串值:
The following will actually compare the string values:
if([date isEqualToString:choosedDate])
这篇关于比较objective-C中的2个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文