title: Reading from reader until a string is reached
body: <p>I am trying to write a function to keep reading from a buffered reader until I hit a certain string, then to stop reading and return everything read prior to that string.</p>
  <p>In other words, I want to do the same thing as <code>reader.ReadString()</code> does, except taking a string instead of a single byte.</p>
  <p>For instance:</p>
  <pre><code>mydata, err := reader.ReadString(&quot;\r\n.\r\n&quot;) //obviously will not compile
  </code></pre>
  <p>How can I do this?</p>
  <p>Thanks in advance,</p>
  <p>Twichy</p>
  <h2>Amendment 1: Previous attempt</h2>
  <p>Here is my previous attempt; its badly written and doesnt work but hopefully it demonstrates what I am trying to do.</p>
  <pre><code>func readDotData(reader *bufio.Reader)(string, error){
  delims := []byte{ '\r', '\n', '.', '\r', '\n'}
  curpos := 0
  var buffer []byte
  for {
      curpos = 0
      data, err := reader.ReadSlice(delims[0])
      if err!=nil{ return &quot;&quot;, err }
      buffer = append(buffer, data...)
      for {
          curpos++
          b, err := reader.ReadByte()
          if err!=nil{ return &quot;&quot;, err }
          if b!=delims[curpos]{
              for curpos &gt;= 0{
                  buffer = append(buffer, delims[curpos])
                  curpos--
              }
              break
          }
          if curpos == len(delims){
              return string(buffer[len(buffer)-1:]), nil
          }
      }
  }
  panic(&quot;unreachable&quot;)
  }
  </code></pre>