Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 11. Working with the String and ... > The StringBuilder Class - Pg. 229

Working with the String and StringBuilder Classes s2 := System.String.Copy(s1); Note that there is a slight difference between these two operations. Executing the following line after performing the operations reveals the difference: Console.WriteLine(System.Object.ReferenceEquals(s1, s2)); Essentially, when using the assignment operator ( := ), you are making a reference assignment. That is, both variables s1 and s2 will reference the same memory space holding the string. The String.Copy() function creates an additional allocation for the string and copies the contents from the first allocation to the second allocation. There are three functions for trimming a string-- String.Trim() , String.TrimStart() , and String.TrimEnd() . The Trim() function removes all occurrences of a set of characters from the beginning and end of a String . TrimStart() and TrimEnd() do the same but only from the beginning and end, respectively. The following code s := '%^ This string has extraneous characters. *)('; s := s.Trim(['%', '(', ')', ' ', '*', '^']); removes the characters specified in the character array from the initial String . The String.PadLeft() and String.PadRight() functions left and right align a specified character to a string for a specified length. So, for instance, the code