我在“aa_bb_cc”中有一个字符串。我想将它转换为单个字符串“aa bb cc”,每个字符串之间的空格为aa,bb和cc。我怎样才能做到这一点 ??感谢。
答案 0 :(得分:10)
您可以使用:
str = [str stringByReplacingOccurrencesOfString:@"_"
withString:@" "];
答案 1 :(得分:3)
NSString* newString = [oldString stringByReplacingOccurencesOfString:@"_" withString:@" "];
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
答案 2 :(得分:3)
使用NSString的 stringByReplacingOccurrencesOfString
NSString *str = @"aa_bb_cc";
[str stringByReplacingOccurrencesOfString:@"_" withString:@""];
答案 3 :(得分:1)
[str replaceOccurrencesOfString:@"_" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [str length])];
答案 4 :(得分:1)
Swift 4.2
@Override
protected void adjustForNumColumns(int numColumns) {
((GridData) c_top.getLayoutData()).horizontalSpan = numColumns;
}
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
/* Layout comments:
*
* component are sequentially filled into numColumns
* by default each component will use 1 column
* GridData can be set to use more that one columns
*/
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
gd.horizontalSpan = numColumns;
c_top = parent;
c_top.setLayoutData(gd);
c_group = new Composite(c_top, SWT.BORDER);
GridLayout newgd = new GridLayout(2, false);
c_group.setLayout(newgd);
c_group.setLayoutData(gd);
// kernel spec combo
Label comboLabel = new Label(c_group, SWT.NONE);
comboLabel.setText("Select kernel");
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
gd.horizontalSpan = numColumns - 1;
comboLabel.setLayoutData(gd);
c_kernelCombo = new Combo(c_group, SWT.READ_ONLY);
gd = new GridData(SWT.FILL, SWT.TOP, true, false);
//gd.horizontalSpan = 1;
c_kernelCombo.setLayoutData(gd);
}
答案 5 :(得分:0)
Swift 2.2:
let input = "upload_FfAPfl-icon.png"
let output = input.stringByReplacingOccurrencesOfString("_", withString: "") // "uploadFfAPfl-icon.png"