Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Creative Commons License 

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern pattern = Pattern.compile("(&\\w+;)");

    public static int computeAdditionalEmptySpacesLength(String text) {
        Matcher matcher = pattern.matcher(text);

        int len = 0;
        while (matcher.find()) {
            // encoded strings represent characters of length "1".
            // (TODO: need to check for any encoded string that represent a character with length more than 1) 
            len += (matcher.group(0).length() - 1);
        }
        return len;
    }
}