C# Strings 1 CNS 3260 C#.NET Software Development.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Java Programming Strings Chapter 7.
CSM-Java Programming-I Spring,2005 String Handling Lesson - 6.
23-Jun-15 Strings, Etc. Part I: String s. 2 About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects,
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
28-Jun-15 String and StringBuilder Part I: String.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
 2006 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
String Escape Sequences
1.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Array String String Builder. Arrays Arrays are collections of several elements of the same type E.g. 100 integers, 20 strings, 125 students, 12 dates,
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
1 9/27/05CS360 Windows Programming Strings, Regex, Web Response.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Regular Expressions.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Built-in Data Structures in Python An Introduction.
C# Regular Expressions C#.Net Software Development Version 1.0.
Overview A regular expression defines a search pattern for strings. Regular expressions can be used to search, edit and manipulate text. The pattern defined.
C# Strings 1 C# Regular Expressions CNS 3260 C#.NET Software Development.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Introduction to Java Java Translation Program Structure
GREP. Whats Grep? Grep is a popular unix program that supports a special programming language for doing regular expressions The grammar in use for software.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 5 Strings CSC1310 Fall Strings Stringordered storesrepresents String is an ordered collection of characters that stores and represents text-based.
CSCI 3327 Visual Basic Chapter 12: Strings, Characters and Regular Expressions UTPA – Fall 2011.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
Java String 1. String String is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
17-Feb-16 String and StringBuilder Part I: String.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
Python Pattern Matching and Regular Expressions Peter Wad Sackett.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Lecture Set 6 The String and DateTime Data Types Part B – Characters and Strings String Properties and Methods.
C# - Strings.
Computer Programming ||
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
Containers and Lists CIS 40 – Introduction to Programming in Python
String Processing Upsorn Praphamontripong CS 1110
University of Central Florida COP 3330 Object Oriented Programming
Strings, Characters and Regular Expressions
Programming in Java Text Books :
String String Builder.
Primitive Types Vs. Reference Types, Strings, Enumerations
String and StringBuilder
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
String and StringBuilder
String and StringBuilder
String and StringBuilder
Introduction to Computer Science
String methods 26-Apr-19.
Strings in Java.
Dr. Sampath Jayarathna Cal Poly Pomona
Visual Programming COMP-315
Switch, Strings, and ArrayLists in Java
String Manipulation.
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

C# Strings 1 CNS 3260 C#.NET Software Development

C# Strings 2 System.String string maps to System.String string maps to System.String Strings are Strings are reference-type objectsreference-type objects Strings are immutableStrings are immutable Strings are sealedStrings are sealed Strings have properties and methods Strings have properties and methods Strings contain 16-bit Unicode characters Strings contain 16-bit Unicode characters

C# Strings 3 Immutability of a string String methods do not modify the string, they return a new string String methods do not modify the string, they return a new string string str = “one two three”; str.Replace(“one”, “1”); str = str.Replace(“one”, “1”); Wrong way Right way

C# Strings 4 Strings are Reference-Types string s1 = null; string reference string s2 = “”; string reference string object contains “” note that: s1 != s2 String variables can be null String variables can be null null is not the same as “” (the empty string) null is not the same as “” (the empty string)

C# Strings 5 Underlying Characters Escape sequences Escape sequences \a- bell\a- bell \b- backspace\b- backspace \t- tab\t- tab \r- carriage return\r- carriage return \n- line feed (new-line)\n- line feed (new-line) \\- backslash\\- backslash \”- double quote\”- double quote Literal string Literal string preceded by by needs no escape charactersneeds no escape characters string s1 string s2 = “C:\\Demo”;

C# Strings 6 Interfaces System.String System.String IComparableIComparable ICloneableICloneable IConvertibleIConvertible IEnumerableIEnumerable

C# Strings 7 Enumerating through a string Contained type is ‘char’ Contained type is ‘char’ string str = “something, something, something”; foreach(char ch in str) { // do work here }

C# Strings 8 String static Members Empty Empty Compare() Compare() CompareOrdinal() CompareOrdinal() Concat() Concat() Copy() Copy() Format() Format() Intern() Intern() IsInterned() IsInterned() Join() Join()

C# Strings 9 string.Empty static property equivalent to “” static property equivalent to “” string str = string.Empty; // means string str = “”;

C# Strings 10 Compare and Concatenation string.Compare(string s1, string s2) string.Compare(string s1, string s2) Returns less-than zero if s1 is lexicographically less-than s2Returns less-than zero if s1 is lexicographically less-than s2 Returns greater-than zero if it’s greaterReturns greater-than zero if it’s greater Returns zero if they are the sameReturns zero if they are the same string.CompareOrdinal string.CompareOrdinal Compares the numeric value of each underlying charCompares the numeric value of each underlying char string.Concat(params object[] strings) string.Concat(params object[] strings) Calls ToString on each object and concatenates themCalls ToString on each object and concatenates them

C# Strings 11 string + and == operators + and == are also defined operators + and == are also defined string s1 = “1”, s2 = “2”; string s3 = s1 + s2; s3 += “hahahaha”; if(s1 == s2) { // do something } if(s1 != s2) { // do something }

C# Strings 12 string.Format() string.Format(string format, params object[] args) string.Format(string format, params object[] args) format is the string to perform the formatting onformat is the string to perform the formatting on format may contain zero or more embedded format itemsformat may contain zero or more embedded format items format items have the following structure:format items have the following structure: {index[,alignment][:formatString]} {index[,alignment][:formatString]} to create a format item, you must have at least “{index}” to create a format item, you must have at least “{index}” args is a list of parameters that will be inserted into the format stringargs is a list of parameters that will be inserted into the format string decimal price = 5.99; string output = string.Format( “Price: {0,-5:C}”, price );

C# Strings 13 Format Items {index[,alignment][:formatString]} {index[,alignment][:formatString]} index refers to the parameter in the params array index refers to the parameter in the params array it is 0-basedit is 0-based alignment alignment requires the comma if usedrequires the comma if used is an integer specifying the minimum widthis an integer specifying the minimum width negative values mean left-justify the valuenegative values mean left-justify the value positive values mean right-justify the valuepositive values mean right-justify the value formatString formatString requires the colon if usedrequires the colon if used is sent to the parameter if it implements IFormattableis sent to the parameter if it implements IFormattable (See StringFormat Demo)

C# Strings 14 IFormattable Overloads the ToString() method Overloads the ToString() method ToString(string format, IFormatProvider formatProvider) Available IFormatProvider classes are: Available IFormatProvider classes are: NumberFormatInfoNumberFormatInfo DateFormatInfoDateFormatInfo

C# Strings 15 Back to string.Format() If the parameter does not accept the stringFormat passed, a FormatException is thrown If the parameter does not accept the stringFormat passed, a FormatException is thrown Items that are not IFormattable will always throw if passed a stringFormatItems that are not IFormattable will always throw if passed a stringFormat If the parameter is not IFormattable, it ignores the stringFormat field If the parameter is not IFormattable, it ignores the stringFormat field If you need to use ‘{‘ or ‘}’ in your string, double them up to escape them: If you need to use ‘{‘ or ‘}’ in your string, double them up to escape them: string str = string.Format(“{{ {0} }}”, 555);

C# Strings 16 string.Join() string.Join(string separator, string[] values) string.Join(string separator, string[] values) joins each of the strings in values separated by separatorjoins each of the strings in values separated by separator string str = string.Join(“:”, new string[] {“1”,”2”,”3”,”4”}); (See StringManipulation Demo)

C# Strings 17 Last 2 Static Members Literal strings are stored in a table called the Intern Pool Literal strings are stored in a table called the Intern Pool saves storagesaves storage speeds up some operationsspeeds up some operations Intern(string str) Intern(string str) if str is already interned, the system reference is returnedif str is already interned, the system reference is returned if str is not interned, it is added to the pool and the new reference is returnedif str is not interned, it is added to the pool and the new reference is returned IsInterned(string str) IsInterned(string str) if str is already interned, the system reference is returnedif str is already interned, the system reference is returned if str is not interned, a null reference is returnedif str is not interned, a null reference is returned

C# Strings 18 Switching on strings The Intern Pool should *theoretically* make switching on strings faster than doing multiple if-else statements The Intern Pool should *theoretically* make switching on strings faster than doing multiple if-else statements but...but... Results from the StringSwitchBench Demo show otherwise: Results from the StringSwitchBench Demo show otherwise: (See StringSwitchingBench Demo)

C# Strings 19 Instance Members Indexer Indexer Length Length EndsWith() EndsWith() Equals() Equals() IndexOf() IndexOf() IndexOfAny() IndexOfAny() Insert() Insert() LastIndexOf() LastIndexOf() LastIndexOfAny() LastIndexOfAny() PadLeft() PadLeft() PadRight() PadRight() Remove() Remove() Replace() Replace() Split() Split() StartsWith() StartsWith() Substring() Substring() ToLower() ToLower() ToUpper() ToUpper() Trim() Trim() TrimStart() TrimStart() TrimEnd() TrimEnd()

C# Strings 20 String Indexer gets the char at the specified location gets the char at the specified location readonly (no set) readonly (no set) string str = “hello world” char ch = str[4];

C# Strings 21 String Equals Equals(string str) Equals(string str) tests the equality of the value of the calling string and strtests the equality of the value of the calling string and str (See InternPool Demo)

C# Strings 22 EndsWith() and StartsWith() EndsWith(string str) EndsWith(string str) returns true if the calling string ends with strreturns true if the calling string ends with str StartsWith(string str) StartsWith(string str) returns true if the calling string starts with strreturns true if the calling string starts with str

C# Strings 23 Searching strings IndexOf (string substr) IndexOf (string substr) Returns the integer index of the first occurrence of substr in the calling stringReturns the integer index of the first occurrence of substr in the calling string LastIndexOf (string substr) LastIndexOf (string substr) Returns the integer index of the last occurrence of substr in the calling stringReturns the integer index of the last occurrence of substr in the calling string IndexOfAny (char[] search) IndexOfAny (char[] search) Returns the integer index of the first occurrence of any of the characters in searchReturns the integer index of the first occurrence of any of the characters in search LastIndexOfAny (char[] search) LastIndexOfAny (char[] search) Returns the integer index of the last occurrence of any of the characters in searchReturns the integer index of the last occurrence of any of the characters in search **Each of these returns -1 if the substring or character cannot be found **Each of these returns -1 if the substring or character cannot be found

C# Strings 24 Insert, Remove, Replace Insert(int position, string str) Insert(int position, string str) Returns a new copy of the calling string with str inserted at positionReturns a new copy of the calling string with str inserted at position Remove(int start, int count) Remove(int start, int count) Returns a new copy of the calling string with the specified section removedReturns a new copy of the calling string with the specified section removed Replace(string oldValue, string newValue) Replace(string oldValue, string newValue) Replace(char oldValue, char newValue) Replace(char oldValue, char newValue) Returns a new copy of the calling string with all instances of oldValue replaced with newValueReturns a new copy of the calling string with all instances of oldValue replaced with newValue

C# Strings 25 Substring() Substring(int start, int count) Substring(int start, int count) Returns a new string with the substring of the calling string from start for count charactersReturns a new string with the substring of the calling string from start for count characters Substring(int start) Substring(int start) Returns a new string with the substring of the calling string from start to the end of the stringReturns a new string with the substring of the calling string from start to the end of the string

C# Strings 26 Padding strings PadLeft(int width) PadLeft(int width) PadLeft(int width, char padChar) PadLeft(int width, char padChar) If the string is shorter than width:If the string is shorter than width: Returns a new copy of the calling string, padding the left side with padChar Returns a new copy of the calling string, padding the left side with padChar If no padChar is specified, space is used If no padChar is specified, space is used PadRight(int width) PadRight(int width) PadRight(int width, char padChar) PadRight(int width, char padChar) If the string is shorter than width:If the string is shorter than width: Returns a new copy of the calling string, padding the right side with padChar Returns a new copy of the calling string, padding the right side with padChar If no padChar is specified, space is used If no padChar is specified, space is used

C# Strings 27 Manipulating Case ToUpper() ToUpper() Returns a new copy of the calling string with all letter characters set to upper-caseReturns a new copy of the calling string with all letter characters set to upper-case ToLower() ToLower() Returns a new copy of the calling string with all letter characters set to lower-caseReturns a new copy of the calling string with all letter characters set to lower-case

C# Strings 28 Trimming Trim() Trim() Returns a new copy of the calling string with all white space removed from the beginning and endReturns a new copy of the calling string with all white space removed from the beginning and end Trim(params char[] trimChars) Trim(params char[] trimChars) Returns a new copy of the calling string with all characters in the trimChars set removed from the beginning and endReturns a new copy of the calling string with all characters in the trimChars set removed from the beginning and end TrimEnd(params char[] trimChars) TrimEnd(params char[] trimChars) Returns a new copy of the calling string with all characters in the trimChars set removed from the endReturns a new copy of the calling string with all characters in the trimChars set removed from the end TrimStart(params char[] trimChars) TrimStart(params char[] trimChars) Returns a new copy of the calling string with all characters in the trimChars set removed from the beginningReturns a new copy of the calling string with all characters in the trimChars set removed from the beginning

C# Strings 29 Split() The opposite of string.Join() The opposite of string.Join() Split(params char[] delimiters) Split(params char[] delimiters) Returns an array of stringsReturns an array of strings Splits the calling string each time it finds any one of the delimitersSplits the calling string each time it finds any one of the delimiters adjacent delimiters split into an empty stringadjacent delimiters split into an empty string The following Example Reads a file in and separates the lines into a string[]: The following Example Reads a file in and separates the lines into a string[]: StreamReader sr = null; try { sr = new StreamReader(“MyFile.txt”); string[] lines = sr.ReadToEnd().Replace(“\r”, “”).Split(‘\n’); } finally { sr.Close(); }

C# Strings 30 Tokenizing a string Tokenizing means splitting into parts Tokenizing means splitting into parts Why not use Split() ?Why not use Split() ? Leaves empty strings sometimes Leaves empty strings sometimes We must know all possible tokens (delimiters) We must know all possible tokens (delimiters) (See SearchingStrings Demo)

C# Strings 31 Tokenizing using IndexOf() Exactly what we want Exactly what we want No Extra Empty stringsNo Extra Empty strings We only need to know what makes up a word (not what doesn’t)We only need to know what makes up a word (not what doesn’t) Not the most elegant code though... Not the most elegant code though... (See SearchingStrings Demo)

C# Strings 32 Introducing Regular Expressions String pattern matching tool String pattern matching tool Regular expressions constitute a language Regular expressions constitute a language C# regular expressions are a language inside a languageC# regular expressions are a language inside a language Used in many languages (Perl most notably) Used in many languages (Perl most notably) There’s a whole class on the theory There’s a whole class on the theory CNS 3240: Computational TheoryCNS 3240: Computational Theory By Chuck AllisonBy Chuck Allison

C# Strings 33 Pattern Matching Match any of the characters in brackets [] once Match any of the characters in brackets [] once [a-zA-Z][a-zA-Z] Anything not in brackets is matched exactly Anything not in brackets is matched exactly Except for special charactersExcept for special characters abc[a-zA-Z]abc[a-zA-Z] Match preceding pattern zero or more times Match preceding pattern zero or more times [a-zA-Z]*[a-zA-Z]* Match preceding pattern one or more times Match preceding pattern one or more times [a-zA-Z]+[a-zA-Z]+

C# Strings 34 Language Elements ()groups patterns ()groups patterns |“or”, choose between patterns |“or”, choose between patterns []defines a range of characters []defines a range of characters {}used as a quantifier {}used as a quantifier \escape character \escape character. matches any character. matches any character ^beginning of line ^beginning of line $end of line $end of line [^]not character specified [^]not character specified

C# Strings 35 Quantifiers *Matches zero or more *Matches zero or more +Matches one or more +Matches one or more ?Matches zero or one ?Matches zero or one {n}Matches exactly n {n}Matches exactly n {n,}Matches at least n {n,}Matches at least n {n,m}Matches at least n, up to m {n,m}Matches at least n, up to m These quantifiers always take the largest pattern they can match These quantifiers always take the largest pattern they can match Lazy quantifiers always take the smallest pattern they can match Lazy quantifiers always take the smallest pattern they can match The lazy quantifiers are the same as those listed above, except followed by a ?The lazy quantifiers are the same as those listed above, except followed by a ?

C# Strings 36 Character Classes \wMatches any word character \wMatches any word character Same as: [a-zA-Z_0-9]Same as: [a-zA-Z_0-9] \WMatches any non-word character \WMatches any non-word character Same as: [^a-zA-Z_0-9]Same as: [^a-zA-Z_0-9] \sMatches any white-space character \sMatches any white-space character Same as: [\f\n\r\t\v]Same as: [\f\n\r\t\v] \SMatches any non-white-space character \SMatches any non-white-space character Same as: [^\f\n\r\t\v]Same as: [^\f\n\r\t\v] \dMatches any digit character \dMatches any digit character Same as: [0-9]Same as: [0-9] \DMatches any non-digit character \DMatches any non-digit character Same as: [^0-9]Same as: [^0-9]

C# Strings 37 Putting It Together Regular Expression for C# identifiers: Regular Expression for C# identifiers: [a-zA-Z$_][a-zA-Z0-9$_]*[a-zA-Z$_][a-zA-Z0-9$_]* Floating Point Numbers: Floating Point Numbers: (0|([1-9][0-9]*))?\.[0-9]+(0|([1-9][0-9]*))?\.[0-9]+ C# Hexidecimal numbers C# Hexidecimal numbers [0][xX][0-9a-fA-F]+[0][xX][0-9a-fA-F]+ ‘words’ in Project 4 ‘words’ in Project 4 [a-zA-Z\-’]+[a-zA-Z\-’]+

C# Strings 38 C# Regular Expressions System.Text.RegularExpressions System.Text.RegularExpressions RegexRegex MatchMatch MatchCollectionMatchCollection CaptureCapture CaptureCollectionCaptureCollection GroupGroup

C# Strings 39 Regex Class Exposes static methods for doing Regular Expression matching Exposes static methods for doing Regular Expression matching Or, holds a Regular Expression as an object Or, holds a Regular Expression as an object Compiles the expression to make it fasterCompiles the expression to make it faster

C# Strings 40 Regex Members The non-static methods echo the static methods The non-static methods echo the static methods Options Options Escape() Escape() GetGroupNames() GetGroupNames() GetGroupNumbers() GetGroupNumbers() GetNameFromNumber() GetNameFromNumber() GetNumberFromName() GetNumberFromName() IsMatch() IsMatch() Match() Match() Matches() Matches() Replace() Replace() Split() Split() Unescape() Unescape()

C# Strings 41 Regex.Options Options Options RegexOptions EnumRegexOptions Enum Compiled – speeds up the searches Compiled – speeds up the searches IgnoreCase IgnoreCase MultiLine MultiLine None None RightToLeft RightToLeft SingleLine SingleLine

C# Strings 42 Regex.Escape() If you’re not sure what needs to be escaped? If you’re not sure what needs to be escaped? Regex.Escape(string pattern) Regex.Escape(string pattern) Returns a new string with the necessary characters escapedReturns a new string with the necessary characters escaped Need to undo it? Need to undo it? Regex.Unescape(string pattern) Regex.Unescape(string pattern) Returns a new string with all escape characters removedReturns a new string with all escape characters removed

C# Strings 43 Matches private Regex re1 = new private string input1 = “ "; Match: Value Index Length Success NextMatch() Captures Groups

C# Strings 44 Linked Matches Follow links using NextMatch() Follow links using NextMatch() Last link Success == false Last link Success == false Match1 NextMatch() Success==true Match2 NextMatch() Success==true Match3 NextMatch() Success==true Match4 NextMatch() Success=false

C# Strings 45 Groups private Regex re1 = new Regex("(([2-9]\d{2})-)?(\d{3})-(\d{4})"); Group: Value Index Length Success Captures Captures a matching substring for future use Captures a matching substring for future use Captures in a Capture objectCaptures in a Capture object Group 0 represents the entire match Group 0 represents the entire match 34

C# Strings 46 Named Groups (? expression) (? expression) Non-capturing group Non-capturing group

C# Strings 47 Captures Capture: Value Index Length private Regex re1 = new "); private Regex re1 = new "); private string input1 = “ "; private string input1 = “ ";

C# Strings 48 Regex.Match() Regex.IsMatch(string input, string pattern) Regex.IsMatch(string input, string pattern) returns true if input matches pattern at least oncereturns true if input matches pattern at least once Regex.Match(string input, string pattern) Regex.Match(string input, string pattern) Returns a Match objectReturns a Match object Use Match.Value to get the string value of the matchUse Match.Value to get the string value of the match Regex.Matches(string input, string pattern) Regex.Matches(string input, string pattern) Returns a MatchCollection of all the occurrences of pattern in inputReturns a MatchCollection of all the occurrences of pattern in input

C# Strings 49 Regex Groups GetGroupNames() GetGroupNames() Returns all the group names in a string[]Returns all the group names in a string[] GetGroupNumbers() GetGroupNumbers() Returns the group numbers in an int[]Returns the group numbers in an int[] GetNameFromNumber() GetNameFromNumber() GetNumberFromName() GetNumberFromName()

C# Strings 50 Regex.Split() Splits the string on a Regular Expression Pattern Splits the string on a Regular Expression Pattern string input = "one%two%%three%%four"; Console.WriteLine(); Console.WriteLine("Split..."); Console.WriteLine(string.Join(",", Console.ReadLine();

C# Strings 51 Regex.Replace Refer to a group capture in the regex using a $ Refer to a group capture in the regex using a $ Replace(string input, string replacement, int count) Replace(string input, string replacement, int count) string input2 = "aaabbbccc:aaabbbccc:aaabbbccc"; Regex re2 = new Regex("(aaa)(bbb)(ccc)"); Console.WriteLine();Console.WriteLine("Replace..."); Console.WriteLine(re2.Replace(input2, "$3$2$1", 1)); Console.ReadLine();

C# Strings 52 Constructing Strings Becuase strings are immutable, building them is slow Becuase strings are immutable, building them is slow Each change creates a new stringEach change creates a new string Use StringBuilder to speed things up Use StringBuilder to speed things up

C# Strings 53 StringBuilder In System.Text In System.Text Contains a mutable string Contains a mutable string Allocates space as needed Allocates space as needed Build the string then call: Build the string then call: myStringBuilder.ToString()myStringBuilder.ToString()

C# Strings 54 StringBuilder Members Capacity Capacity Indexer Indexer Length Length Append() Append() AppendFormat() AppendFormat() Insert() Insert() Remove() Remove() Replace() Replace() ToString() ToString()