{"id":349,"date":"2011-12-05T18:25:27","date_gmt":"2011-12-05T18:25:27","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=349"},"modified":"2011-12-05T20:37:56","modified_gmt":"2011-12-05T20:37:56","slug":"escaping-spaces-in-a-properties-file-in-java","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2011\/12\/05\/escaping-spaces-in-a-properties-file-in-java\/","title":{"rendered":"Escaping spaces in a Properties file in Java"},"content":{"rendered":"<p><strong>Problem 1:<\/strong><\/p>\n<p>Can you escape keys or values in a properties file? Yes. Use backslash \\ as the escape character.<br \/>\nSo <em>Hello World=foo<\/em> should be written as <em><strong>Hello\\ World=foo<\/strong><\/em><br \/>\nWikipedia has an excellent <a href=\"http:\/\/en.wikipedia.org\/wiki\/.properties\">article<\/a> <\/p>\n<p><strong>Problem 2:<\/strong><\/p>\n<p>You might most probably use the <strong>String replaceAll(String <em>regex<\/em>, String replacement)<\/strong> method. So how do you escape spaces?<\/p>\n<blockquote><p>\n\/\/ This Will NOT WORK !!<br \/>\n<del datetime=\"2011-12-05T18:18:01+00:00\"><strong>String escaped = &#8220;Hello World&#8221;.replaceAll(&#8221; &#8220;, &#8220;\\\\ &#8220;); <\/strong><\/del><\/p>\n<p>\/\/ This is the right way to do it, since we need to work with regex<br \/>\n<strong>String escaped = &#8220;Hello World&#8221;.replaceAll(&#8220;\\\\s&#8221;, &#8220;\\\\\\\\ &#8220;); <\/strong>\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Problem 1: Can you escape keys or values in a properties file? Yes. Use backslash \\ as the escape character. So Hello World=foo should be written as Hello\\ World=foo Wikipedia has an excellent article Problem 2: You might most probably use the String replaceAll(String regex, String replacement) method. So how do you escape spaces? \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/349"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=349"}],"version-history":[{"count":6,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":355,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/349\/revisions\/355"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}