I have this line:
(ADDRESS = (PROTOCOL = XXX)(HOST = YYY)(PORT = ZZZ))
that I need to retrieve the HOST name which is in this case YYY.
I don’t know if it will be written in lowercase or uppercase or even a mix between them.
So I switch the whole line to uppercase by line.toUpperCase() and then I split the line according to HOST = and I pick the characters until I get ) which indicates the end of the host name.
I’m sure there is a better way to do this. Any hints will be appreciated.
My code:
String host = "";
line = line.toUpperCase();
int i = line.indexOf("HOST");
while(line.charAt(i)!='=')
i++;
while(line.charAt(i)!=')') {
i++;
if(line.charAt(i)!=')'&&line.charAt(i)!=' ')
host = host + line.charAt(i);
}
return host;
Try