0
Hello guys I would like to know how I can capture the last 5 characters of a link, for example in this link below I would like to capture the characters ". m3u8"
https:painel.iptvmove.com:25461/live/teste/1234/1224.m3u8
0
Hello guys I would like to know how I can capture the last 5 characters of a link, for example in this link below I would like to capture the characters ". m3u8"
https:painel.iptvmove.com:25461/live/teste/1234/1224.m3u8
1
Just use the method substring.
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 values (whether 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) );
}
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
Also check that the string size is greater than 5
– Peres
Thank you very much!
– MisterdroidTM