public static String sortCommonTokens(String column){
  StringBuilder order=new StringBuilder();
  order.append(" (CASE ");
  for (  String token : commonTokens) {
    order.append(" WHEN " + column + " LIKE '"+ token+ " %'"+ " THEN SUBSTR("+ column+ ","+ String.valueOf(token.length() + 2)+ ")"+ " || ', "+ token+ "' ");
  }
  order.append(" ELSE " + column + " END) ");
  return order.toString();
}

public static String sortCommonTokens ( String column ) { StringBuilder order = new StringBuilder ( ) ; order . append ( " (CASE " ) ; for ( String token : commonTokens ) { order . append ( " WHEN " + column + " LIKE '" + token + " %'" + " THEN SUBSTR(" + column + "," + String . valueOf ( token . length ( ) + 2 ) + ")" + " || ', " + token + "' " ) ; } order . append ( " ELSE " + column + " END) " ) ; return order . toString ( ) ; }
given column create sqlite column expression to convert any sorttokens prefixes to suffixes eg . column = " title " , commontokens = { " the " , " an " , " a " } ; ( case when title like ' the % ' then substr ( title , 5 ) | | ' , the ' when title like ' an % ' then substr ( title , 4 ) | | ' , an ' when title like ' a % ' then substr ( title , 3 ) | | ' , a ' else title end ) this allows it to be used in sql where a column expression is expected ( select , order by )
