Home  |  Delphi .net Home  |  Framework String Handling
 .NET Framework
 Namespace References

 System.Drawing - download only

 Articles and Tutorials

 Overview of .NET
 Delphi and .NET
 Winform Applications
 ASP .Net Applications
 ASP Web Services
 Framework Collections
 Framework String Handling
 Framework Files and Folders

 Author links

 Buy Website Traffic at

 Buy Proxies at

 Framework String Handling
Strings are different in the .Net framework
Native Delphi Strings are primitive data types. In the .Net environment, they are mapped to the System.String class. Unlike other classes, strings objects do not have to be explicitly constructed - the declaration is sufficient.
Strings with the same value are in reality the same string object - references to the string point to the same object.
This is possible because in .Net, strings are 'immutable'. This means that any changes to them result in the creation of a new string object. The old string object is discarded if it is no longer referenced.

String methods use 0 indexing
In essence, the string class provides methods that are equivalent to the StrUtils run time library of functions and procedures, except that they are now methods of the string object itself.
But be warned that these methods treat the string as being 0 indexed. You have the confusing (but unavoidable) situation where direct string access uses 1 based indexing :
   s : String;
   s := 'ABC';

Yields :

but where System.Class methods use 0 based indexing :
   s : String;
   s := 'ABC';
   Console.WriteLine(s.SubString(2, 1));

Yields :

This necessary evil is for reverse compability with the existing Delphi syntax and applications.
The System.String class provides some functionality over and above that provided by StrUtils. For example, to be able to split a string into parts according to a separator character, and to add padding characters to the start or end of the string.

Strings always comprise UniCode characters
Native Delphi supports strings comprising single characters - .Net is International in flavour and supports only 2-byte UniCode characters. This allows languages such as Chinese to be fully supported.

StringWriter and StringReader classes
The .Net Framework System.IO namespace contains these two oddball classes. They are not really IO (Input/Output) classes, since they only work on data in memory.
They allow a string to be read or written character by character, or line by line. In the latter case, the 'lines' of characters are all contained in the single string. Each line is delimited by line termination characters. On Windows Operating Systems, the line termination string comprises of line feed (Chr(10)) and carriage return (Chr(13)) characters.
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page