title: Best way to shorten UTF8 string based on byte length
body: <p>A recent project called for importing data into an Oracle database.  The program that will do this is a C# .Net 3.5 app and I'm using the Oracle.DataAccess connection library to handle the actual inserting.</p>
  
  <p>I ran into a problem where I'd receive this error message when inserting a particular field:</p>
  
  <p>ORA-12899 Value too large for column X</p>
  
  <p>I used <code>Field.Substring(0, MaxLength);</code> but still got the error (though not for every record).</p>
  
  <p>Finally I saw what should have been obvious, my string was in ANSI and the field was UTF8.  Its length is defined in bytes, not characters.</p>
  
  <p>This gets me to my question.  What is the best way to trim my string to fix the MaxLength?</p>
  
  <p>My substring code works by character length.  Is there simple C# function that can trim a UT8 string intelligently by byte length (ie not hack off half a character) ?</p>