-3

Hi i need a basic java program. My input is ___This___is___the___sample___program___ and i want output as This_is_the_sample_program. Underscores are dynamic. There may be 3 or more or less than 3 underscores between the strings. but the output should look like THis_is_the_sample_program.

Please help me if anybody knows

Thanks in advance.

4

1 回答 1

1

看看以下内容:StringBuilderString#split()

StringBuilder sb = new StringBuilder();
String[] split = "___This___is___the___sample___program___".split("_");
int i = 0;
for (; i < split.length - 1; i++) {
    if (split[i].length() > 0) {
        sb.append(split[i]).append("_");
    }
}
System.out.println(sb.append(split[i]));
于 2013-08-03T09:08:50.210 回答