title: How to get the last index of a specific character before a different one
body: <p>Sorry, It's kinda hard to explain it for me.</p>
  
  <p>I want to get the index of the last <em>new line</em> character which placed before a different character in a <code>C#</code> application.</p>
  
  <p>for example, I want the index of the <code>\n</code> which is placed before <code>Hi</code></p>
  
  <pre><code>"\n\n\n\n\nHi\n\n\n"
  </code></pre>
  
  <p>Also I want the first index of <code>\n</code> which is placed after <code>Hi</code>.</p>
  
  <p>I know <a href="https://msdn.microsoft.com/en-us/library/system.string.lastindexof%28v=vs.110%29.aspx" rel="nofollow">String.LastIndexOf</a> has multiple ways to use. I just don't know if I can <em>or how to</em> use it to get what I want.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is what I've came up to so far.</p>
  
  <pre><code>int firstIndex=myString.IndexOf("\n")==0 ? 0 : -1;
  int secondIndex=myString.Text.Trim().IndexOf("\n");
  </code></pre>
  
  <p>I want to know if there's a better or more standard way to do that.</p>