Java tutorial
//package com.java2s; public class Main { /** * Does one string contain another, starting at a specific offset? * @param text * @param offset * @param other * @return */ public static int matchesAt(CharSequence text, int offset, CharSequence other) { int len = other.length(); int i = 0; int j = offset; for (; i < len; ++i, ++j) { char pc = other.charAt(i); char tc = text.charAt(j); if (pc != tc) return -1; } return i; } }