Created
October 2, 2019 00:01
-
-
Save luisdeol/8ae625287b52096864b35bf74b9d901a to your computer and use it in GitHub Desktop.
2.7: Search Strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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