Get the first/last token from a path
/**
* This software is provided as IS by Antilia-Soft SL.
* Copyright 2006-2007.
*/
//package com.antilia.common.util;
public class StringUtils {
public static String getFirstToken(final String path, final String separator)
{
if (path == null)
return null;
final int index = path.indexOf(separator);
if (index == -1)
return path;
return path.substring(0, index);
}
public static String getLastToken(final String path, final String separator)
{
if (path == null)
return null;
final int index = path.lastIndexOf(separator);
if (index == -1)
return path;
if (index+1>=path.length())
return "";
return path.substring(index+1);
}
}
Related examples in the same category