Below is a small extract of a very large file.
I'm looking for a way to get each name and value (on the Name(x) and Value(x) lines) into an element of a Array or List type with an "=" between the two.
i.e to get each element to look like " 'name' = 'value' ".
[Device|EEP_FEATUREKOI_HFS_Max|Kostia]
--------------------------------
Name(1) = partHeader_A01
Value(1) = 0x10
Desc(1) = (Address 0x000) Article No. / P.C.B No Byte 1
Name(2) = partHeader_A02
Value(2) = 0x9
Desc(2) = (Address 0x001) Article No. / P.C.B No Byte 2
Name(3) = partHeader_A03
Value(3) = 0x95
Desc(3) = (Address 0x002) Article No. / P.C.B No Byte 3
Name(4) = partHeader_A04
Value(4) = 0x38
Desc(4) = (Address 0x003) Article No. / P.C.B No Byte 4
----------------------------------
Name(12) = AdrIctPcbTestDate_Day
Value(12) = 0xFF
Desc(12) = (Address 0x00B) Test Date : Day
---------------------------------
Name(13) = AdrIctPcbTestDate_Month
Value(13) = 0xFF
Desc(13) = (Address 0x00C) Test Date : Month
---------------------------------
Name(14) = AdrIctPcbTestTime_Hour
Value(14) = 0xFF
Desc(14) = (Address 0x00D) Test Time : Hour
---------------------------------
Name(15) = AdrIctPcbTesTime_Minute
Value(15) = 0xFF
Desc(15) = (Address 0x00E) Test Time : Minute
So far I can get the names and values. My problem is, when a section has more than 1 byte(denoted with a "_" in the name) I need to place all the byte values in the same element with only one name.
I can't figure out the proper algorithm to get this to work right.
i.e, for partHeaderArtLK_A01 up to partHeaderArtLK_A04, instead of having
partHeaderArtLK_A01 = 10
partHeaderArtLK_A02 = 09
partHeaderArtLK_A03 = 95
partHeaderArtLK_A04 = 38
The element would should to look like
partHeaderArtLK = 10 09 95 38.
(Note: I inserted the dashed line seperators to make things clearer. They don't (and cannot) exist in the actual file.)
Here's my attempt so far:
if (line.contains("Name")&& line.contains("_")) {
String basicName = line;
cutName = basicName.split("=")[1].trim();//get substring after '='
cutName = cutName.substring(0,cutName.lastIndexOf("_"));//removes '_'?
importantName.add(i, (cutName + " = "));//add to element i
System.out.println("Line reads: " + basicName);
System.out.println("Part: " + cutName);
do{
if (line.contains("Value")) {
Hex = line.split("=")[1].trim();//get substring after '='
importantNumber.add(i, Hex);//get substring after '='
System.out.println("Value: " + Hex);
}//end if
}while(!"Value".contains(line = reader.readLine()));
while (!placeToFinish[i].equals(line = reader.readLine()));
}else
if(line.contains("Name")) {
String basicName = line;
cutName = basicName.split("=")[1].trim();//get substring after '='
importantName.add(i, (cutName + " = "));//get substring after '='
System.out.println("Line reads: " + basicName);
System.out.println("Part: " + cutName);
System.out.println("Number: " + importantNumber.indexOf(i) + "\n");
do{
if (line.contains("Value")) {
Hex = line.split("=")[1].trim();//get substring after '='
importantNumber.add(i, Hex);//get substring after '='
}//end if
}while (!"Value".contains(line = reader.readLine()));
while (!placeToFinish[i].equals(line = reader.readLine()));
}//end if
Here's the link to the full code: http://justpaste.it/d3u0
All algorithms or code is appreciated.
Thanks in advance!