Roland Turner

about | contact

Java idiom for removing suffixes

Just because I keep finding myself writing this snippet of code to convince myself that have it correct (error checking not included…):

String full = "/some/where.mail";
String suffix = ".mail";

String prefix = full.substring(0, full.indexOf(suffix));

assert prefix.equals("/some/where");