nick
BAN USERI cannot paste the solution since the editor is not allowing me to submit it with "links" in it.
But still you need to use a combination of methods from String, Character and StringBuffer classes to get the work done.
first: detect if there is a "protocol" present in the given string by taking a substring of the given url and doing a string comparison.
if there is "protocol" - then check if that is upper case by extracting each character upto first 4 chars from the url and using
Character.isUpperCase(char) method to detect the case and string.replace (char, char) to replace uppercase char with lowercase char
if there is no "protocol" - then create a string buffer of the url and insert chars ( h, t, t, p, :, /, /) at the first 6 positions
now we know that since 0 to 6 is "protocol" then the host name and so on starts with 7.
create a while loop and travel thru the url till u hit 47 (ASCII for / ). As you traverse the url, do the same thing we did above ( checking for upper case of character)
when you reach the "/" char you will get its value in the string (for given example ) the "/" is at 21
use this value to and url.lenght() to create a new substring containing - /index,html
then using replaceAll method, replace that substring with an empty string.
use this same technique to get the substring containing "//" and replace it with "/"
I hope I was clear enough..sorry could not paste the code.
& is bitwise operator and && is logical operator.
- nick February 14, 2013In a&b the bitwise operator checks both the left hand side and right hand side bit by bit and compares.
The logical operator on the other hand operates on the boolean values of the variables.
In a && b, the logical operator first checks the left hand side i.e. a and if its true then only it checks b.