Android String Merge mergeBlank(String s)

Here you can find the source of mergeBlank(String s)

Description

merge Blank

Declaration

public static String mergeBlank(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static String mergeBlank(String s) {
        int numberBlank = 0;
        String a1;//from w  w w  .  j av a 2s  .  c  o  m
        String a2;
        for (int index = 0; index < s.length(); index++) {
            numberBlank = getBlankNumber(s, index);
            if (numberBlank >= 2) {
                a1 = s.substring(0, index);
                a2 = s.substring(index + numberBlank - 1, s.length());
                s = a1 + a2;
            }
        }
        return s;
    }

    public static int getBlankNumber(String s, int index) {
        if (index < s.length()) {
            if (s.charAt(index) == ' ') {
                return getBlankNumber(s, index + 1) + 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
}

Related

  1. combineBlank(String str)