helps in removing a certain string

Asked

Viewed 132 times

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 whole set of strings containing the occurrence name= an arraylist of objects. After its storage, I will 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();

within the arraylist of objects was stored this (I had it printed 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 is this: As I look for the string name, then as I do to remove all its previous and later contents from the second quote, for example:

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

to pegaValorName become only: pg4

  • And php where your problem is?

  • 1

    it is.. I removed php from tags

  • I have a huge form in php (I have 40 forms to develop, the number of questions goes up to the number 100 and the nomenclature varies a lot), I’m making a code to make my life easier when creating the database (with create table). the idea is to read index.php (for now I’m doing it in .txt), take all name="something" and generate create table automatically. If there is another way to implement this, whether in java, php or another language, it would be open for help. But I accepted the modification.

  • Have you ever seen a library called Jsoup?

1 answer

2


I’m no expert on Java, but that should do it:

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 it working here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.