Created
May 4, 2020 14:41
-
-
Save Zulcom/66cd739de14fa787b6e4bfead8642862 to your computer and use it in GitHub Desktop.
С# - есть ли в данном слове заданная подстрока
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 functions | |
{ | |
class Program | |
{ | |
static string prompt(string question) | |
{ | |
Console.WriteLine(question); // пишем запрос в консоль | |
return Console.ReadLine(); // возвращаем ввод от пользователя в переменную | |
} | |
static string myAwesomeFunction(string strToProcess, string strTofind) | |
{ | |
if (strToProcess.Contains(strTofind)) // Читай https://docs.microsoft.com/ru-ru/dotnet/api/system.string.contains?view=netcore-3.1 | |
{ | |
return ""; | |
} | |
else | |
{ | |
return "not "; | |
} | |
} | |
static void Main(string[] args) | |
{ | |
var strToProcess = prompt("Type in string to process:"); // где ищем | |
var strTofind = prompt("Type in substring to find:"); // что ищем | |
var result = myAwesomeFunction(strToProcess, strTofind); | |
Console.WriteLine("'{0}' {1}contains in '{2}'", | |
strTofind, | |
result, | |
strToProcess | |
); | |
// собираем строчку на вывод - число в фигурных скобках равно номеру аргумента который туда подставится: | |
// {чтоИскали} {Резултат функции} contains in {гдеИщем} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment