Duvida com STRING

1 resposta
F

Olá galera,

meu problema é o seguinte:

tenho uma certa String: “<html> texto texto<head> texto texto</head>texto</html>”

gostaria de saber como faço um método para ele me retornar a mesma String, porém sem as tags HTML. ja tentei, porem está dando erros. alguem poderia me ajudar??

1 Resposta

E

opa beleza?

segue um exemplo simples, adaptado:
public class StringTeste &#123;

    public StringTeste&#40;&#41; &#123;
        
        String input = &quot;&lt;html&gt; texto texto&lt;head&gt; texto texto&lt;/head&gt;texto&lt;/html&gt;&quot;;
        String result = this.replace&#40; input, &quot;&lt;html&gt;&quot;, &quot;&quot; &#41;;
        result = this.replace&#40; result, &quot;&lt;/html&gt;&quot;, &quot;&quot; &#41;;
        
        System.out.println&#40; result &#41;;
    &#125;

    public String replace&#40;String str, String pattern, String replace&#41; &#123;
        int s = 0;
        int e = 0;
        StringBuffer result = new StringBuffer&#40;&#41;;
    
        while &#40;&#40;e = str.indexOf&#40;pattern, s&#41;&#41; &gt;= 0&#41; &#123;
            result.append&#40;str.substring&#40;s, e&#41;&#41;;
            result.append&#40;replace&#41;;
            s = e+pattern.length&#40;&#41;;
        &#125;
        result.append&#40;str.substring&#40;s&#41;&#41;;
        return result.toString&#40;&#41;;
    &#125;
    
    public static void main&#40; String&#91;&#93; args &#41; &#123;
        new StringTeste&#40;&#41;;
        System.exit&#40;0&#41;;
    &#125;
    
&#125;
Replacing Substrings in a String :wink:

abraços

Criado 8 de maio de 2006
Ultima resposta 9 de mai. de 2006
Respostas 1
Participantes 2