objective c - How do you compare different strings in an If loop? -
how compare 2 strings different format strings? example, in code below:
str1 = [datadic1 objectforkey:[finalarray objectatindex:indexpath.row]]; str1 contains 124.00,120/70-14,1,759,140/70-14,48.8 x 57.0. str2 = [datadic2 objectforkey:[finalarray objectatindex:indexpath.row]]; str2 contains 1.00,90/90-6,1,250,90/90-6,45.3 x 87.0.
i want compare str1
, str2
if ([bike1str intvalue] < [bike2str intvalue]){ nslog(@"%@", str2); } else{ }
for example: if (120/70-14 < 90/90-6)
how do type comparison ?
datadic1 { "displacement_trim" = "124.00 "; "dry_weight" = "<null>"; "front_brakes_size_trim" = "260 "; "front_tire_size" = "120/70-14"; "fuel_capacity_trim" = "13.50 "; "overall_height_trim" = "1,759 "; "overall_length_trim" = "2,230 "; power = ""; "power_weight_ratio" = "<null>"; "rear_brake_size_trim" = "240 "; "rear_tire_size" = "140/70-14"; stroke = ""; "torque_trim" = ""; "stroke_trim" = "48.8 x 57.0 "; }
and finalarray
( power_weight_ratio, rear_brake_size_trim, dry_weight, torque_trim, stroke_trim, rear_tire_size, front_brakes_size_trim, fuel_capacity_trim, overall_length_trim, front_tire_size, stroke, power, displacement_trim, overall_height_trim )
not float values asking all values compare
nsmutabledictionary *dict1,*dict2; nsmutablearray *arraycontaingfloat; dict1 = [[nsmutabledictionary alloc]init]; dict2 = [[nsmutabledictionary alloc]init]; arraycontaingfloat = [[nsmutablearray alloc]init]; [dict1 setobject:[nsnumber numberwithfloat:14.20] forkey:@"displacement_trim"]; [dict2 setobject:[nsnumber numberwithfloat:20.20] forkey:@"displacement_trim"]; if ( [[dict1 valueforkey:@"displacement_trim"] compare:[dict2 valueforkey:@"displacement_trim"]]==nsorderedascending) { nslog(@"dict 2 greater"); }else{ nslog(@"dict 1 greater"); } if( [[dict1 valueforkey:@"displacement_trim"] compare:[dict2 valueforkey:@"displacement_trim"]]==nsorderedascending){ } [arraycontaingfloat addobject:[dict1 valueforkey:@"displacement_trim"]]; [arraycontaingfloat addobject:[dict2 valueforkey:@"displacement_trim"]]; nslog(@"array conting float %@",arraycontaingfloat); nssortdescriptor *highesttolowest = [nssortdescriptor sortdescriptorwithkey:@"self" ascending:no]; [arraycontaingfloat sortusingdescriptors:[nsarray arraywithobject:highesttolowest]]; nslog(@"after sorting %@",arraycontaingfloat);
you output this:
dict 2 greater array conting float ( "14.2", "20.2" ) after sorting ( "20.2", "14.2" )
let me know if have further query.
Comments
Post a Comment