문제

i've problem with nsstring hasprefix

for example. i've string like this

NSString *data= @"NZDIDR,NZDIDR,9571,9593,9571,IDR,2013-09-23 21:45:25.0,CUR",

if([clean hasPrefix:@"CUR"]||[clean hasPrefix:@"cur"]){
     NSLog(@"yep! there is CUR");
}
else{
   NSLog(@"no there is!");
}

the result should be"yep! there is CUR" right? is that error on my method?

도움이 되었습니까?

해결책

What you mean to do is check for a suffix. A prefix is at the start of the string, a suffix is at the end.

Also, your code checks for a prefix on the object clean not data.

Try:

if ([data hasSuffix:@"CUR"]) {
  NSLog(@"Suffix found.");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top