在我的介绍性Objc课程中,这是一个简单的挑战,这让我感到非常悲痛.我已经尝试了一些我在X-code API中选择的东西试图解决这个问题,但我没有运气.挑战规范包括限制:我不能更改for循环之外的任何代码,我的输出不能包含尾随逗号.它目前的迭代确实如此,我不知道如何摆脱它!
以下是当前形式的代码:
NSString *outputString = @"";
int loopMaximum = 10;
for (int counter = 1; counter <= loopMaximum; counter++) {
outputString = [NSString stringWithFormat:@"%@ %d,", outputString, counter];
//Not sure how to get rid of trailing comma =/
}
NSLog(@"%@", outputString);
Run Code Online (Sandbox Code Playgroud) 我正在尝试将月/日/年元素中的字符串连接成一个显示MM/DD/YYYY的值,但我找不到在xslt 1.0中执行此操作的方法,该方法将包含'/'分隔符.在xslt 2.0中使用字符串连接函数的方式.我需要在不创建新模板或使用变量/ if-logic的情况下执行此操作,因为我们尚未在课堂上"学习".我试图连接的代码部分如下所示:
<publishedDate>
<month>7</month>
<day>9</day>
<year>2007</year>
</publishedDate>
Run Code Online (Sandbox Code Playgroud)
目前我能做的最好的是:
<xsl:value-of select="concat(
format-number(publishedDate/month, '##00', 'date'),
format-number(publishedDate/day, '##00', 'date'),
format-number(publishedDate/year, '####', 'date')
)"/>
Run Code Online (Sandbox Code Playgroud)
哪个输出日期如下:03082014
与此同时,为了完成任务,我不得不使用一个看似如下的可怕,冗长的解决方法:
<xsl:value-of select="format-number(publishedDate/month, '##00', 'date')"/>/
<xsl:value-of select="format-number(publishedDate/day, '##00', 'date')" />/
<xsl:value-of select="format-number(publishedDate/year, '####', 'date')" />
Run Code Online (Sandbox Code Playgroud)
并正确输出(即03/08/2014).你们知道使用1.0功能获得此输出的方法吗?谢谢!