help on how to remove a particular string

2

test content.txt

<td><input type="radio" name="pg1" value="SIM" /></td>
<td><input type="radio" name="pg1" value="NÃO" /></td>
<td><input type="radio" name="pg2" value="SIM" /></td>
<td><input type="radio" name="pg2" value="NÃO" /></td>
<td><input type="radio" name="pg3" value="SIM" /></td>
<td><input type="radio" name="pg3" value="NÃO" /></td>
<td><input type="radio" name="pg4" value="SIM" /></td>
<td><input type="radio" name="pg4" value="NÃO" /></td> 

In this program it saves the entire set of strings containing the name= occurrence within an arraylist of objects. After its storage, I'll do the processing of each string.

    Reader lerArquivo = new FileReader("teste.txt");
    BufferedReader br2 = new BufferedReader(lerArquivo);
    ArrayList<Perguntas> valores = new ArrayList<>();

    String linha;
    String delims = "\"";

    while ((linha = br2.readLine()) != null) {

        if (linha.contains("name=")) {

            Perguntas form = new Perguntas();
            form.setNomeDaPergunta(linha);
            valores.add(form);

        }

    }
    System.out.println("valores.size()-> " + valores.size());
    //fazendo o tratamento das strings
    for (int i = 0; i < valores.size(); i++) {

        System.out.println("-> " + valores.get(i).getNomeDaPergunta());
    }

    lerArquivo.close();
    br2.close();

Inside the object arraylist was stored (I had to print what I had inside the arraylist of objects)

<td><input type="radio" name="pg1" value="SIM" /></td>
<td><input type="radio" name="pg1" value="NÃO" /></td>
<td><input type="radio" name="pg2" value="SIM" /></td>
<td><input type="radio" name="pg2" value="NÃO" /></td>
<td><input type="radio" name="pg3" value="SIM" /></td>
<td><input type="radio" name="pg3" value="NÃO" /></td>
<td><input type="radio" name="pg4" value="SIM" /></td>
<td><input type="radio" name="pg4" value="NÃO" /></td> 

my question: How do I search for the string name, then how do I remove all of its contents before and after the second quotation mark, for example:

String pegaValorName = "<td><input type=\"radio\" name=\"pg4\" value=\"NÃO\" /></td>"; 

a pegaValorName becomes only: pg4

    
asked by anonymous 25.05.2015 / 02:55

1 answer

2

I'm not a Java expert, but this should resolve:

String pegaValorName = "<td><input type=\"radio\" name=\"pg4\" value=\"NAO\" /></td>"; 
String partes[] = pegaValorName.split("name=\"");
partes = partes[1].split("\"");
String valorName = partes[0];
System.out.println(valorName);

You can see working here .

    
25.05.2015 / 04:45