本文介绍了Objective-C右填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家都希望有人可以提供帮助.我正在浏览网络,似乎没有任何意义:S
hello all hope someone can help with that. I was browsing the net and nothing really seems to make sense :S
所以我有一个字符串可以说:"123"
,我想使用类似的功能:
so I have a string lets say:"123"
and I would like to use a function like:
padr("123", 5, 'x')
,结果应为:
"123xx"
对不起,但是Objective-C是处理字符串:S
Sorry but Objective-C is a nightmare when dealing with strings :S
推荐答案
您可以创建自己的方法来获取初始字符串,所需的长度和填充字符(正如我刚开始做的&在其他类似文章中所描述的)问题)
You could create your own method to take the initial string, desired length, and padding character (as I was starting to do & also described in a few similar questions)
或者您可以使用Apple已经提供的NSString方法;)
Or you could use the NSString method Apple already provides ;)
NSString *paddedString = [@"123"
stringByPaddingToLength: 5
withString: @"x" startingAtIndex:0];
请参见此方法的NSString类参考.
这篇关于Objective-C右填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!