-2

how to extract values from .properties file, having two values corresponding to one property name Example of property file is

iFrame=className=demo-frame

DateTextBox=id=datepicker

datePicker=xpath="//td[not(contains(@class,'ui-datepicker-other-month'))]/a[text()='"+value+"']"

Q: main help required for 3rd property as value contains special characters as well.

Dude
  • 692
  • 1
  • 4
  • 25
Jagdeep Kaur
  • 21
  • 1
  • 6

2 Answers2

2

You can have your values comma-separated:

DateTextBox=id,datepicker
String[] dates = properties.getProperty("DateTextBox").split(",");
Hussein Zawawi
  • 2,907
  • 2
  • 26
  • 44
  • Thanks for this answer. Do following property also work with it: datePicker=xpath, "//td[not(contains(@class,'ui-datepicker-other-month'))]/a[text()='"+value+"']" As it contains comma in 2nd value itself. – Jagdeep Kaur May 12 '15 at 08:36
0

You can use a combination of substring and indexOf methods to get the desired results:

prop.getProperty("datePicker").
    substring(prop.getProperty("datePicker").
        indexOf("=", prop.getProperty("datePicker").indexOf("="))+1)

In this second indexOf provides first occurence of = which is utilised by enclosing indexOf to start its search from returned index. This in turn provides index of second = thus makes easy to capture substring.

P.S. it will work for all keys in your properties file.

Vivek Singh
  • 3,641
  • 2
  • 22
  • 27