1

I have webpage with this simple text, which is changeable.

<html><head><style type="text/css"></style></head><body>69766</body></html>

I need parse only number 69766 and save it to variable as String or int. It's possible to parse this number without adding libraries?

Thanks for your questions !

3 Answers 3

2

You can do like this

    URL url = new URL("http://url for your webpage");
    URLConnection yc = url.openConnection();
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            yc.getInputStream()));
    String inputLine;
    StringBuilder builder = new StringBuilder();
    while ((inputLine = in.readLine()) != null) 
        builder.append(inputLine.trim());
    in.close();
    String htmlPage = builder.toString();

    String yourNumber = htmlPage.replaceAll("\\<.*?>","");
Sign up to request clarification or add additional context in comments.

Comments

0

For your basic need you should take a lot at Html class.

2 Comments

But how can I parse text and save it into variable for displaying in TextView?
You're right, you can do as @Arun suggest or try jsoup witch is a third-party lib but it seems pretty easy to use.
0

this link shows how to parse the xml with the SAX parser. Its pretty straight forward. http://www.codeproject.com/Articles/334859/Parsing-XML-in-Android-with-SAX

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.