2013-05-08 122 views
0

我有兩個ID如何比較兩個ID

85816465-FA7B-48B1-8AD3-7FB0A1B6C011 - 85816465-fa7b-48b1-8ad3-7fb0a1b6c011 

正如你可以看到,他們幾乎是相同的,但有區別)

85816465-FA7B-48B1-8AD3-7FB0A1B6C011驗證碼我對這個代碼

CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault); 
    NSString * uuidString = (__bridge NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId); 
    CFRelease(newUniqueId); 

在此之後編譯其插入到數據庫(Postgres的)和數據庫將其轉換到這個

85816465-fa7b-48b1-8ad3-7fb0a1b6c011 

當我選擇這個插入的Id,並試圖與舊的比較,Xcode給我,他們不相等... 有什麼建議嗎?

+0

請出示你的Postgres的表定義 – mvp 2013-05-08 08:21:15

+1

相關:http://stackoverflow.com/questions/5089997/how-to-compare-two-case-insensitive-strings – mvp 2013-05-08 08:24:06

回答

1

當你比較字符串並將其轉換爲大寫字母,如果是使用方法

uuidString=[uuidString uppercaseString]; 
+0

謝謝大家,但我只是高呼情況下,它很棒) – Arthur 2013-05-08 09:15:58

0

請儘量使用一個唯一的diffrence ...我希望它可以幫助你

NSString *str1 = @"85816465-FA7B-48B1-8AD3-7FB0A1B6C011"; 
NSString *str2 = @"85816465-fa7b-48b1-8ad3-7fb0a1b6c011"; 

str1 = [str1 stringByReplacingOccurrencesOfString:@"-" withString:@""]; 
str2 = [str2 stringByReplacingOccurrencesOfString:@"-" withString:@""]; 

if([str1 caseInsensitiveCompare:str2] == NSOrderedSame) 
    NSLog(@"ITS EQUAL"); 
else 
    NSLog(@"ITS NOT EQUAL"); 
0

試試這個

NSRange r = [udidstring1 rangeOfString:udidstring2 options:NSCaseInsensitiveSearch]; 

    if(r.location != NSNotFound) 
    { 
     NSLog(@"Both UDID are same"); 
    } 

,或者你可以試試這個

if ([udidstring1 caseInsensitiveCompare:udidstring2]==NSOrderedSame) { 
      NSLog(@"Both UDID are same"); 
    }