xcode 如何在iphone中连接三个字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10994343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:25:53  来源:igfitidea点击:

How to concatenate three string in iphone

iphonexcode

提问by The Developer

I have three string and I want them to concatenate but they are not concatenating. I am using this code.

我有三个字符串,我希望它们连接但它们没有连接。我正在使用此代码。

I want my last string to display like this:

我希望我的最后一个字符串显示如下:

Cerenia Results 12Jun 2012.pdf

Cerenia 结果 2012 年 6 月 12 日.pdf

like this

像这样

NSString *fileName = @"Cerenia Results";

NSString* str = [formatter stringFromDate:date]; 

NSString*extention=@".pdf";


NSString * strRR = [NSString stringWithFormat:@"Cerenia Results_%@ [%@].pdf", extension];

回答by Future2020

General case: to concatenate all three strings you should use

一般情况:要连接您应该使用的所有三个字符串

NSString * strRR = [NSString stringWithFormat:@"%@%@%@", fileName, str, extension];

Your case:

你的情况

You can add any formatting you like such as inserting characters in between (to get the results you are after >> Cerenia Results 12Jun 2012.pdf)

您可以添加任何您喜欢的格式,例如在中间插入字符(以获得您想要的结果 >> Cerenia 结果 12Jun 2012.pdf)

[formatter setDateFormat:@"ddMMMyyyy"]
NSString* fileName = @"Cerenia Results";
NSString* str = [formatter stringFromDate:date];
NSString* extension = @"pdf";
NSString* strRR = [NSString stringWithFormat:@"%@ %@.%@", fileName, str, extension];

回答by Paresh Navadiya

Do this:

做这个:

 [formatter setDateFormat:@"ddMMMyyyy"]
 NSString* str = [formatter stringFromDate:date]; 
 NSString * strRR = [NSString stringWithFormat:@"Cerenia Results %@.pdf",str];

回答by TheTiger

You can append string using "stringByAppendingFormat" ...

您可以使用“ stringByAppendingFormat”附加字符串...

[formatter setDateFormat:@"ddMMMyyyy"]
NSString* fileName = @"Cerenia Results";
NSString* str = [formatter stringFromDate:date];
NSString* extension = @".pdf";
NSString* strRR = [[fileName stringByAppendingFormat:str]stringByAppendingFormat:extension];