Hello everyone, I would like to know how I can capture the last 5 characters of a link, for example in this link I would like to capture the characters ".m3u8"
link
Hello everyone, I would like to know how I can capture the last 5 characters of a link, for example in this link I would like to capture the characters ".m3u8"
link
Just use the substring method. .
String.substring(tamanho da string - 5);
Ex:
String uri = "https://painel.iptvmove.com:25461/live/teste/1234/1224.m3u8";
System.out.print( uri.substring(uri.length() - 5) );
As well remembered by @Ronaldo Peres, always validate the values (either with the help of libraries, regex etc).
String uri = "https://painel.iptvmove.com:25461/live/teste/1234/1224.m3u8";
/* Validação com a classe URL */
try {
new URL(uri);
System.out.print( uri.substring(uri.length() - 5) );
} catch (MalformedURLException e) {
System.out.println( "URL Inválida" );
}
/* Validação com a classe URLUtil */
if (URLUtil.isNetworkUrl(uri)) {
System.out.print( uri.substring(uri.length() - 5) );
}
/* Verificação do tamanho da URL */
if (uri.length >= 5) {
System.out.print( uri.substring(uri.length() - 5) );
}