Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, September 3, 2019

Codecademy Get Parts of Strings 6/8


// Sample Solution
using System;

namespace NameGrab
{
  class Program
  {
    static void Main(string[] args)
    {
      // User Name
      string name = "Farhad Hesam Abbasi";

      // Get first letter
      int firstNamePosition = name.IndexOf("Farhad");
char firstLetter = name[firstNamePosition];

      // Get last name
int lastNamePosition = name.IndexOf("Abbasi");
      string lastName = name.Substring(lastNamePosition);

      // Print results
Console.WriteLine($"{firstLetter}. {lastName}");

    }
  }
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts