java - StringBuffer find 'start' and 'end' and write anything between them -


stringbuffer find 'start' , 'end' , write between them

example:

text1 text2 start text3 text4 end text5 

can print out of stringbuffer text3 , text4' text between 'start' , 'end'

assumming have stringbuffer sb contains text:

int start = sb.indexof("start"); int end = sb.indexof("end"); if (start != -1 && end != -1) {     string fragment = sb.substring(start + "start".length(), end);     system.out.println(fragment); } 

note finds text between "start" , "end" asked in question. if text in stringbuffer has line breaks, might want search text between "start\n" , "end\n".


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -