Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created October 2, 2019 00:01
Show Gist options
  • Save luisdeol/8ae625287b52096864b35bf74b9d901a to your computer and use it in GitHub Desktop.
Save luisdeol/8ae625287b52096864b35bf74b9d901a to your computer and use it in GitHub Desktop.
2.7: Search Strings
using System;
namespace _27_ManipulateStrings
{
public class Program
{
static void Main(string[] args)
{
const string phrase = "Luis would love to have free time to release articles weekly. Give me time...";
var timeIndexOf = phrase.IndexOf("time");
var lastIndexOf = phrase.LastIndexOf("time");
var startsWith = phrase.StartsWith("Luis");
var endsWith = phrase.EndsWith("Luis");
var substring = phrase.Substring(timeIndexOf, "time".Length);
Console.WriteLine($"Index using IndexOf: {timeIndexOf}");
Console.WriteLine($"Index using LastIndexOf: {lastIndexOf}");
Console.WriteLine($"Does the phrase starts with 'Luis'? {startsWith}");
Console.WriteLine($"Does the phrase ends with 'Luis'? {endsWith}");
Console.WriteLine($"Substring from index {timeIndexOf} with length {"time".Length}: {substring}");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment