char x = '\u0041';Prints out the character A.
Console.WriteLine("x= {0}",x);
for (int i = 0; i < s.Length; i++)
{
char c = s[ i ];
}
The string type has a ToCharArray() method that outputs an array of chars. That's not something you'll use a lot but it comes in handy with Trim() (see later). Example two shows mixing Unicode Chars with strings and printing the characters out individually or all at once using the foreach statement. We'll return to foreach as it not only a compact and less buggy way of enumerating through a string or collection, it is essential for classes that implement IEnumerable. Plus foreach also works with char arrays like this.
char[] chars ={'*','!','^' };
foreach(char c in chars)
Console.Write("{0}", c);
Using StringBuilder
When working with strings, you are likely to be doing- Reading/Writing Strings from/to Disk
- Building strings.
- Comparing Strings
string s="abcdefg";You'll get an error "Property or indexer 'string.this[int]' cannot be assigned to -- it is read only". The way to do this is with Replace() as in
s[3]='z';
s= s.Replace('d', 'z');Doing small string operations is inefficient if done often as each time causes a new String to be created. You can get away with one or two Replaces but any more and you should use the StringBuilder class.
On the next page StringBuilder for Efficiently Building Strings

