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
Post a Comment