如何分配到的NSString对象与变量的NSString? [英] How to assign to the nsstring object a NSString with variables?

查看:104
本文介绍了如何分配到的NSString对象与变量的NSString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

long mins = 02; long secs = 35;
  NSString *allTime = [[NSString alloc]init];
    allTime = @"%i:%i",mins, secs ;

不过,这并不工作,因为当我尝试显示的NSString对象,我得到这个:%I:%I
相反的,我想:02:35

But it doesn't work, because when I try to display that nsstring object I got this: %i:%i Instead of that I want to get: 02:35

如何做到这一点?
谢谢!

How to do that ? Thank you!

allTime = [NSString stringWithFormat:@"%l/%l", mins, secs];
for(Playlists *thePL in collection)
    {
        NSLog(@"===NEXT PLAYLIST===");
        NSLog(@"Name: %@", thePL.namePL);
        NSLog(@"Quantity of songs: %i", thePL.entries);
        NSLog(@"Total of time: %@",thePL.allTime);
    }

时间总计:L

推荐答案

您需要使用 stringWithFormat ,见<一href=\"https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html\"><$c$c>NSString类参考

allTime = [NSString stringWithFormat:@"%d:%d",mins, secs];

这篇关于如何分配到的NSString对象与变量的NSString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆