Thursday, April 18, 2013

Selenium : Find the last occurence of "/" in the URL

                                    Find the last occurence of "/" in the URL



import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;

public class url_backslash
{

 public static void main(String[] args)
 {
  String sUrl=JOptionPane.showInputDialog("enter url");
  Boolean bFlag=false;
  int i;
  String sReverse=StringUtils.reverse(sUrl);
  for ( i=0 ;i<=sUrl.length()-1;i++)
  {
   //if (Character.toString(sReverse.charAt(i)) ==  "/")  //Convert character to string
   if (sReverse.charAt(i)== "/".charAt(0))
   {
    bFlag=true;
    break;
   }
  }

  if ( bFlag = true )
  {
   System.out.print("the last '/' exists @ "+(sUrl.length()- i));
  }
  else
  {
   System.out.print("/ does not exists");
  }
 }

}
 

No comments:

Post a Comment