NSString stringWithFormat with tabs instead of spaces

本秂侑毒 提交于 2019-12-12 12:25:05

问题


You can see that I add 40 spaces after my string but it starts at index 0. Can I do the same thing with tab "\t" instead of spaces " "?

NSString *firstString = [[NSString stringWithFormat:@"%@",stringToWrite] stringByPaddingToLength:40 withString:@" " startingAtIndex:0];

回答1:


Yes @"\t" will put tab instead of spaces.
Also, your line could be a bit more simple :

NSString *firstString = [stringToWrite stringByPaddingToLength:40
                                                    withString:@" "
                                               startingAtIndex:0];


来源:https://stackoverflow.com/questions/6860633/nsstring-stringwithformat-with-tabs-instead-of-spaces

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!