class DnParser {

  public static String substring(final String dn, final int beginIndex)
  {
    if (beginIndex < 0) {
      throw new IndexOutOfBoundsException("beginIndex cannot be negative");
    }

    final List<LdapAttribute> attrs = convertDnToAttributes(dn);
    if (beginIndex >= attrs.size()) {
      throw new IndexOutOfBoundsException("beginIndex cannot be larger than the number of RDNs");
    }

    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < attrs.size(); i++) {
      if (i >= beginIndex) {
        final LdapAttribute la = attrs.get(i);
        sb.append(la.getName()).append("=").append(la.getStringValue()).append(",");
      }
    }
    if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ',') {
      sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
  }

  private  DnParser();

}