title: How to find if HL7 Segment has ended or not if Carriage return is not present
body: <p>I am working on a tool which will construct a HL7 message in following Way :</p>
  
  <p>Message will start with : 0B
  Segment will end with : OD
  And Message will end with : 1C0D</p>
  
  <p>So, here i have reached so far, i am able to add OB and add 1C0D in the end of the HL7 Message. I am also able to add OD before at the end of the segment. I am accomplishing with the of code where i will check if Character before Segment name is 0D or not.</p>
  
  <p>But the issue is if text in the message is somewhat like this ...PID| my code will add 0D before PID| which is not correct it should check if its the start of the segment or not.</p>
  
  <p>Please help if someone has worked on similar requirement.</p>
  
  <p>Link to my code is :
  <a href="https://stackoverflow.com/questions/34787347/arraylist-sublist-indexoutofbounds-exception">Arraylist Sublist IndexOutOfBounds Exception</a></p>