Advertisement
karlakmkj

String Manipulation

Nov 17th, 2020
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. //Task: To transform this sentence so that the first two words (Close on) are in all caps and the rest is lower case.
  2.  
  3. using System;
  4.  
  5. namespace MovieScript
  6. {
  7.   class Program
  8.   {
  9.     static void Main(string[] args)
  10.     {
  11.       // Script line
  12.       string script = "Close on a portrait of the HANDSOME PRINCE -- as the BEAST'S giant paw slashes it.";
  13.  
  14.       // Get camera directions - using string properties
  15.       int charPosition = script.IndexOf("Close");
  16.       int length = "Close on".Length;
  17.       string cameraDirections = script.Substring(charPosition, length);
  18.  
  19.       // Get scene description
  20.       charPosition = script.IndexOf("a portrait");
  21.       string sceneDescription = script.Substring(charPosition);
  22.  
  23.       // Make camera directions uppercase
  24.       cameraDirections = cameraDirections.ToUpper();
  25.  
  26.       // Make scene description lowercase
  27.       sceneDescription = sceneDescription.ToLower();
  28.  
  29.       // Print results using interpolation
  30.       Console.WriteLine($"{cameraDirections} {sceneDescription}");
  31.     }
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement