I need to define an array containing below all special characters..
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \
I am using this
List<String> specialCharactersInSolr = Arrays.asList(new String[] {
"+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^",
"~", "*", "?", ":", });
It is accepting all the character except " and \
Please help how to define these two as well.
\ and " are special characters in String class
" is start or end of String\ is used to create some characters like new lines \n \r tab\t or to escape special characters like in your case \ and "So to make them literals you will have to escape them with "\\" and "\""
Other idea is to use Character[] instead of String[] so you wont have to escape " and yours characters can be written as '"' or '\\' (because ' require escaping - it should be written as '\'' - \ is also special here and will also require escaping to produce its literal).
Use this
List<String> specialCharactersInSolr = Arrays.asList(new String[]{
"+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^",
"~", "*", "?", ":","\"","\\"});
here "\"" and "\\" are for " and \
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With