I am having trouble removing new line character that appears in the line.
My input is:
1,john,a
2,smith,b
3,mike
,c
4,clark,d
My output should be:
1,john,a
2,smith,b
3,mike,c
4,clark,d
Below is the code I wrote so far. I am using "continue" to remove bad records based on count of expected "," in each line. However, I would like to concatenate the line where "\n" exists wrongly with the next line to get the line instead of removing as bad record.
String test="1,john,a\n2,smith,b\n3,mike\n,c\n4,clark,d";
String[] test2=test.split("\n");
int count=0;
String s="";
for(int i=0;i<=test2.length-1;i++)
{
for(int j=0;j<test2[i].length();j++) {
char c= test2[i].charAt(j);
if(c==',') {
count++;
if(count<2) {
continue;
}
System.out.println(test2[i]);
}
}
count=0;
}
[[3,"mike","c"],[4,"clark","d"]]and not[[3,"mike\n,c,4,clark","d"]]? If at all possible, the best solution is to change the way these values are getting encoded in the first place.\n,or,\nwith""