Examples

Example 1

using System;

namespace Samples
{
  public class StringSample
  {
    public static void Main()
    {
      string s = "Hello World!";
      Console.WriteLine("\"{0}\".Length: {1}",
                        s, s.Length);
      Console.WriteLine("\"{0}\".ToUpper(): {1}",
                        s, s.ToUpper());
      Console.WriteLine("\"{0}\".ToLower(): {1}",
                        s, s.ToLower());
      char c = 'l';
      Console.WriteLine("\"{0}\".IndexOf({1}): {2}",
                        s, c, s.IndexOf(c));
      int i = 5;
      Console.WriteLine("\"{0}\".IndexOf({1}, {2}): {3}",
                        s, c, i, s.IndexOf(c,i));
      Console.WriteLine("\"{0}\".LastIndexOf({1}): {2}",
                        s, c, s.LastIndexOf(c));
    }
  }
}
The output is
 "Hello World!".Length: 12 "Hello World!".ToUpper(): HELLO WORLD! "Hello World!".ToLower(): hello world! "Hello World!".IndexOf(l): 2 "Hello World!".IndexOf(l, 5): 9 "Hello ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.