title: Is there a better way to remove a trailing part of string in .NET?
body: <p>For removing trailing part is I use the code</p>
  
  <pre><code>str.substring(0,str.length -2) 
  </code></pre>
  
  <p>Is there a better way? I especially dislike using str.length.</p>
  
  <p><strong>Edit</strong>
  I wanted the question to be as short and simple as possible and I supposed that I just overlooked some String method. I try to be more precise.</p>
  
  <p>I need to remove given number of characters from the end of a string. I don't want to care what the characters are and I don't want to introduce a risk of removing more characters.</p>
  
  <p>If the number is larger then string length let's there is an exception (the string should be validated earlier).</p>
  
  <p>I don't have the problem especially with length, but with referencing a variable twice (imagine a function instead of a variable). I also don't like necessity of subtraction but it is only a personal preference.</p>
  
  <p><strong>VB.NET soution</strong></p>
  
  <p>The question is taged vb.net so there is vb.net code (should be in a module):</p>
  
  <pre><code>&lt;System.Runtime.CompilerServices.Extension&gt; _
  Public Shared Function RemoveFromEnd(stringValue As String, removedCharacters As Integer) As String
      Return stringValue.Substring(0, stringValue.Length - removedCharacters)
  End Function
  </code></pre>