String Jquery or JS

0

Example:

var question1="What is nuclear physics"; var question2="What is nuclear physics"

In case I would like to always pick up what is after what is or what it means.

Thanks,

    
asked by anonymous 14.07.2018 / 17:17

3 answers

2

Use the split of the javascript itself

oque = "o que é física nuclear";
significa = "o que significa física atômica";

cortaOque = oque.split("é")[1];
console.log(cortaOque); //saída: física nuclear

cortaSignifica = significa.split("significa")[1]; 
console.log(cortaSignifica); //saída: física atômica
    
14.07.2018 / 17:31
1

You can use the substring function as described below in the code. It removes the previous 7 characters. To learn more about this feature, see w3schools .

    
       function myFunction() {
        var str = "O que é física nuclear";
        var res = str.substring(7);
        document.getElementById("demo").innerHTML = res;
    }
      
   
    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to extract characters from the string.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
     </body>
    </html>
    
14.07.2018 / 17:42
0

You can do this: defines two variables, var o_q_eh = 'O que é:' and var o_q_significa = 'O que Significa '; . waiting for you to use the html label to create the question text ... <label></label> would look like this: <label id="pergunta1">O que é física nuclear</label>

use jquery to get the text of id="pergunta1" using: var pergunta1 = $('#pergunta1').text(); then use substring to remove what you need, or concatenate the variables: var o_q_eh; and var o_q_significa with the rest of the text of each <label> you need. If I understood what you need ...

    
14.07.2018 / 17:36