多くの質問を読んでから、私はあなたが望むものを理解できると思います。
出発点があるように思わ:
NSLog(@"add string is: %@",addString);// result is: 45,1
と現在の終点は次のとおりです。
NSLog(@"myInt is: %d",myInt);// result is: 45
しかし、それはあなたがまだ45,1
をプリントアウトしたいようですマイこれは、arrayyyy
と呼ばれる2つの文字列[@ "45"、@ "1"]の配列を持ち、両方の値を整数として出力したいと考えています。これがそう、私はあなたが欲しいと思うものですされている場合:
NSInteger myInt1 = [[arrayyyy objectAtIndex:0] intValue];
NSInteger myInt2 = [[arrayyyy objectAtIndex:1] intValue];
NSLog(@"add string is: %d,%d",myInt1,myInt2);
注、アレイ内の少なくとも2つの文字列が存在しない場合、これはNSRangeExceptionと恐ろしくクラッシュします。
NSInteger myInt1 = -1;
NSInteger myInt2 = -1;
if ([arrayyyy length] >0) myInt1 = [[arrayyyy objectAtIndex:0] intValue];
if ([arrayyyy length] >1) myInt2 = [[arrayyyy objectAtIndex:1] intValue];
NSLog(@"add string is: %d,%d",myInt1,myInt2);
をしかし、それは-1
のガード値が実際のデータに存在しないことを前提としていても、これは悪いです。だから、非常に少なくとも、あなたが行う必要があります。
結果が45であればよく、そのintに変換されます。 [addString intValue] intに変換し、[addString integerValue]をNSIntegerに変換します。 –
http://stackoverflow.com/questions/4791470/convert-nsstring-to-nsinteger – bdparrish
@ user993223「文字列を整数に変換する」とはどういう意味ですか?達成したい結果は何ですか? –