After all, if you create a huge string??”say, some
megabytes in size, such as a base64-encoded large image??”you don??™t want that data to be
copied in order to create a string from it. However, once you create the System.String, you
now have the System.String and the StringBuilder holding references to the same array of
characters. Since System.String is immutable, the StringBuilder??™s internal character array
now becomes immutable as well. StringBuilder then switches to using a copy-on-write
idiom with that buffer. Therefore, at the place where you append to the StringBuilder after
having created the built1 string instance, the StringBuilder must make a new copy of the
internal character array, thus handing off complete ownership of the old buffer to the built1
System.String instance. It??™s important to keep this behavior in mind if you??™re using
StringBuilder to work with large string data.
Searching Strings with Regular Expressions
The System.String type offers some rudimentary searching methods, such as IndexOf(),
IndexOfAny(), LastIndexOf(), LastIndexOfAny(), and StartsWith(). Using these methods, you
can determine if a string contains certain substrings and where. The .NET Framework also
contains classes that implement regular expressions (regexes).
Pages:
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313