oOOMIAO 2013-07-29 08:11 采纳率: 10%
浏览 927

对字符串进行格式设置

需要对输出字符串设置格式,这样可以将URL和内容分开显示。请指教。

代码:NSLog(@"Description %@", string);

输出字符串:

2013-07-28 11:13:59.083 RSSreader[4915:c07] Description         
http://www.apple.com/pr/library/2013/07/23Apple-Reports-Third-Quarter-Results.html?sr=hotnews.rss
Apple today announced financial results for its fiscal 2013 third quarter ended
June     29, 2013. The Company posted quarterly revenue of $35.3 billion and quarterly 
net profit of $6.9 billion, or $7.47 per diluted share. 
Apple sold 31.2 million iPhones, which set a June quarter record. 
  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-09 14:19
    关注

    要格式化输出字符串,可以使用printf函数或者NSString的stringWithFormat方法。


    例如,你可以使用以下代码来格式化输出字符串:

    NSLog(@"URL: %@", urlString);
    NSLog(@"Content: %@", contentString);
    

    或者:

    NSLog(@"URL: %@\nContent: %@", urlString, contentString);
    

    或者:

    NSString *formattedString = [NSString stringWithFormat:@"URL: %@\nContent: %@", urlString, contentString];
    NSLog(@"%@", formattedString);
    

    其中,%@是占位符,表示后面的字符串会替换占位符。


    还有很多其他的占位符,比如%d表示整数,%f表示浮点数等。详情可以参考Apple的文档:String Format Specifiers。

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型