[SOLVED] How to read a file and compare Array values
Hello friends!
I have a problem which i'm stuck on.
I have 2 sets of Arrays. Lets call them ArrayA and ArrayB.
They both contains values like 29396590, 29396591, 29396592 etc.
The idea is, if a value in ArrayA is found, it is replaced with the value in ArrayB.
ArrayA[0] = ArrayB[0]
ArrayA[1] = ArrayB[1] and so on..
I have a text file that contains lots of information. When I read in the text file, I need to be able to check each line for all the values in ArrayA. If one is found then it needs to be replaced with the corresponding value in ArrayB.
I'm using String replace if I find a value but i'm finding it hard to make it loop through ArrayA. The code I am using is causing errors and I cant figure out why :confused:
This is the code I currently have:
Code:
FileInputStream in = new FileInputStream(file.txt);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null){
for(int a = 0; a < myarrayA.length; a++){
if (strLine.contains(myarrayA[a])){
strLine = strLine.replaceAll(myarrayA[a], myarrayB[a]);
}
}
System.out.println(strLine);
}
The problem is making it loop through ArrayA looking for the values..
Here is an example of the txt file:
Code:
29396590;SIT PORT ;CHF; -14247.54;CHF;
29396591;SIT PORT ;EUR; 7363.11;EUR;
29396592;SIT PORT ;EUR; 12372.86;EUR;
29396593;SIT PORT ;JPY; -967715.56;JPY;
29396598;SIT PORT ;USD; -3746876.81;USD;
29396625;SIT PORT ;USD; 20354218.51;USD;
I hope you understand all that!! Thanks in advance for any help.