Escaping spaces in a Properties file in Java

Writing by shivdev on Monday, 5 of December , 2011 at 6:25 pm

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?

// This Will NOT WORK !!
String escaped = “Hello World”.replaceAll(” “, “\\ “);

// This is the right way to do it, since we need to work with regex
String escaped = “Hello World”.replaceAll(“\\s”, “\\\\ “);

Leave a comment

Category: Java

MySQL converting MAC Address to a Number

Writing by shivdev on Friday, 2 of December , 2011 at 12:36 am

Here’s an example of converting a Mac Address 01:23:45:67:89:ab into a decimal number (1250999896491), using the MySQL conv() function.

The idea is select CONV(’0123456789ab’, 16, 10); 01:23:45:67:89:ab without the :

select CONV(REPLACE(SUBSTR(’01:23:45:67:89:ab’, INSTR(’01:23:45:67:89:ab’, ‘(‘)+1, 17),’:',”),16,10);

Results In: 1250999896491

Leave a comment

Category: SQL Server

Shivdev Kalambi's Blog

Shivdev Kalambi is a Principal Software Engineer working at ArcSight. He has over 11 years' experience in software development and has worked with several technologies and played different roles and contributed to all phases of projects. Other non-tech activies include Ping-pong, Racquetball, Rock Climbing at PG and Swimming.