Java - Write code to get substring In Between

Requirements

Write code to get substring In Between

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String name = "book2s.com";
        String prefix = "b";
        String delimiter = ".";
        System.out.println(substringInBetween(name, prefix, delimiter));
    }/*from  w ww  .java  2s .co  m*/

    public static String substringInBetween(String name, String prefix,
            String delimiter) {

        int startPos = 0;
        if (prefix != null)
            startPos = prefix.length() + 1;

        int endPos = name.indexOf(delimiter, startPos);
        if (endPos > 0)
            return name.substring(startPos, endPos);

        return null;
    }
}

Related Exercise