Question

i got this issue and i don't know how to solve it. Here is the problem:

1 - i have a data in my database who i split into a strings[] and then i split this strings[] into another 2 strings[] (even and odd lines). Everything works fine but when i want to join all the lines into a single String i got a multi line string intead of a single line. Someone can help me?

data

abcdef//
123456//
ghijkl//
789012

code:

String text = "";
vec1 = data.split("//"); //split the data
int LE = 0;
for (int a = 0; a < vec1.length; a++) { //verify how many even and odds line the data have
if (a % 2 == 0) { //if 0, LE++
    LE++;
}
}
resul1 = new String[LE];
int contA = 0, contB = 0;
for (int c = 0; c < resul1.length; c++) {
    if (c % 2 != 0) {
        text += " " + resul1[c].toLowerCase().replace("Á","a").replace("Ã","a").replace("ã","a").replace("â","a").replace("á","a").replace("é","e").replace("É","e")
                        .replace("ê","e").replace("í","i").replace("Í","i").replace("ó","o").replace("Ó","o").replace("õ","o").replace("Õ","o").replace("ô","o").replace("Ô", "o")
                        .replace("Ú","u").replace("ú","u").replace("ç","c").replace("_","").replace("<","").replace(">","");
        contA++;
    }
}

And the String looks like

abcdef
ghijkl

instead of

abcdefghijkl
Was it helpful?

Solution

You should use replaceAll() method.

text.replaceAll("\\r\\n|\\r|\\n", ""); // the method removes all newline characters
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top