I have some Strings in java, which come from an ontology file and they have the format:
<owl:onProperty rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#WHAT_WE_WANT"/>
I need to make a function that finds if a specific String value is included in WHAT_WE_WANT and then returns the String WHAT_WE_WANT.
So, I splitted every line of the ArrayList at “#”, then I searched for the String value into the second part of the splitted lines. Now all I have to do is to get rid of “/>.
I was trying to split in ” symbol, but I cannot do it, because when I write “”” the compiler does not recognize that ” is the String symbol I need. Any ideas?
In case my word-explanation was not very good, here is my code:
if (nextLine.matches(".*" + lookUp + ".*" ))
{String lala[]=nextLine.split("#");
for(int i=0;i<lala.length;i++){
if(lala[i].matches(".*"+lookUp+".*")){
String[] temp=lala[i].split( """ ); //<--- doesn't work :/
System.out.println(temp[0]);
}
}
}
This will give a compilation error:
because the string literal is malformed. If you want to split where there is a double-quote character you need to escape the double-quote.
In a string literal, an unescaped double quote means “this is the end of the string”. So the compiler will think that you have written an empty String (
"") followed by an unterminated String literal (" );. When it reaches the end of the line, the compiler complains that the string is not terminated … because a Java String literal cannot span multiple lines.The stuff that you are trying to decode is OWL … which means you could (and maybe should) parse it using an OWL parser, and RDF parser or an XML parser … rather than bashing it with regexes, etcetera.