java - Replacing String parts -
this topic has been discussed here lot, none of solution worked me. want replace part of string, got html. getting , displaying html works fine, cann't remove parts of string. acts doesn't find it.
please, have @ code bellow:
public class main extends activity { public static string url = ""; public static string htmlstring; public textview maintext; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main_layout); maintext = (textview) findviewbyid(r.id.maintext); constructurl(); gethtml(); htmlstring.replaceall("<head>", "hulo"); maintext.settext(htmlstring); } public void gethtml() { try { httpclient httpclient = new defaulthttpclient(); httpcontext localcontext = new basichttpcontext(); httpget httpget = new httpget(url); httpresponse response = httpclient.execute(httpget, localcontext); bufferedreader reader = new bufferedreader( new inputstreamreader( response.getentity().getcontent() ) ); string line = null; while ((line = reader.readline()) != null){ htmlstring += line + "\n"; } } catch (exception e) { } } public void constructurl() { time time = new time(); time.settonow(); string year = converttostring(time.year - 2000); string month = converttostring(time.month + 1); string monthday = converttostring(time.monthday); url = "http://www.gymzl.cz/bakalari/suplovani_st/tr" + year + month + monthday + ".htm"; } public string converttostring(int value) { string text = ""; if(value < 10) text = "0"; text += string.valueof(value); return text; } }
the 'hulo' replacement doesn't seem work.
i sorry such long code, have tried everything.
replaceall
not update calling string, need assign back. change
htmlstring.replaceall("<head>", "hulo");
to
htmlstring = htmlstring.replaceall("<head>", "hulo");
Comments
Post a Comment