Find occurence of last "/" in an URL without using string reverse function(built in function)
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
public class url_bkslah_nrev
{
public static void main(String[] args)
{
String sUrl=JOptionPane.showInputDialog("enter Url");
Boolean bFlag=false;
int i;
for( i=sUrl.length()-1; i>=0 ; i--) // Do if true until false
{
if (StringUtils.mid(sUrl, i, 1).charAt(0) == "/".charAt(0)) //converting to character
{
bFlag=true;
break;
}
}
if (bFlag=true)
{
System.out.print("/ exists at "+(i+1));
}
else
{
System.out.print("/ not exists");
}
}
//1/3/56/'
}
No comments:
Post a Comment