
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Pruning Characters from the Head and/or Tail of a String
|
77
The StringBuilder object also contains a Length property, which, if increased,
appends spaces to the end of the existing
StringBuilder object’s string. If the Length
is decreased, characters are truncated from the StringBuilder object’s string. Increas-
ing the
Length property can increase the Capacity property, but only as a side effect.
If the
Length property is increased beyond the size of the Capacity property, the
Capacity property value is set to the new value of the Length property. This property
acts similarly to the
Capacity property:
sb.Length = 200;
The String and StringBuilder objects are considered nonblittable,
which means that they must be marshaled across any managed/
unmanaged boundaries in your code. The reason is that strings have
multiple ways of being represented in unmanaged code, and there is
no one-to-one correlation between these representations in unman-
aged and managed code. In contrast, types such as
byte, sbyte, short,
ushort, int, uint, long, ulong, IntPtr, and UIntPtr are blittable types
and do not require conversion between managed and unmanaged
code. One-dimensional arrays of these blittable types, as well as struc-
tures or classes containing only blittable types, are also considered
blittable and ...