我试图删除使用php一起使用的多个逗号。这是代码:
$var = "Hello, welcome, when,,,,,,, ."
$str = preg_replace('/,+/', '', $var);
显示输出为:
Hello welcome when .
但预期产出是:
Hello, welcome, when.
答案 0 :(得分:0)
您正在替换''。你应该这样做:
private string CreateGraphicString() {
StringBuilder builder = new StringBuilder();
int row, column;
for (row = 0; row <= 6; row++) {
for (column = 0; column <= 6; column++) {
if ((column == 1 && row != 0 && row != 6) ||
((row == 0 || row == 6) && column > 1 && column < 5) ||
(row == 3 && column > 2 && column < 6) ||
(column == 5 && row != 0 && row != 2 && row != 6))
builder.Append("*");
else
builder.Append(" ");
}
builder.AppendLine();
}
builder.AppendLine();
}
return builder.ToString();
}
myLabel.Text = builder.AppendLine();
myTextbox.Text = builder.AppendLine();
其中有一个或多个 preg_replace('/,+/', ',', $var);
替换为一个,
,