Twitter4j ANdroid App problem

Put your problem here if it does not fit any of the other categories.

Twitter4j ANdroid App problem

Postby shakey » Mon Feb 20, 2012 8:40 pm

Hi I am designing an Android Twitter App. I want to know how can I get the return info from the getSource() function to display just the source of the tweet and not the html. Is this something I would have to do on the Android side or is it already built into Twitter4j.

My function is returning and displaying for example,

< a href="http://blackberry.com/twitter" rel="nofloow">Twitter for Blackberry</a>

and all I want to return is
Twitter for Blackberry
shakey
Freshman
Freshman
 
Posts: 9
Joined: Sat Oct 02, 2010 1:33 pm

Top

Re: Twitter4j ANdroid App problem

Postby Phyll » Tue Feb 21, 2012 12:05 am

Hi shakey,

In the case of what you are showing us here you could simply do a couple of substrings to get to that:

< a href="http://blackberry.com/twitter" rel="nofloow">Twitter for Blackberry</a>

String s = "< a href=\"http://blackberry.com/twitter\" rel=\"nofloow\">Twitter for Blackberry</a>";
s = s.substring(s.indexOf(">")+1); //cuts off everything before Twitter
s = s.substring(0, s.indexOf("<")); //everything from the first char to less than

Ignore the escaped quotes, I just had to do that to make it work from an assignment like this. You can use this on your string without doing anything to it like the escapes.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Twitter4j ANdroid App problem

Postby shakey » Tue Feb 21, 2012 5:45 am

Thank Phil

I got it figured out earlier today.

By taking the returned html string and trimming it with regex.

I do appreciate your help though .

Your code will probably come in handy for future projects.
shakey
Freshman
Freshman
 
Posts: 9
Joined: Sat Oct 02, 2010 1:33 pm

Re: Twitter4j ANdroid App problem

Postby Phyll » Tue Feb 21, 2012 11:39 am

Hi shakey,

Maybe you'd like to share how you used trim to solve this problem. I for one would like to see how that works.

Thanks,

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 26 guests