Skip to content

Instantly share code, notes, and snippets.

@Zulcom
Created May 4, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zulcom/66cd739de14fa787b6e4bfead8642862 to your computer and use it in GitHub Desktop.
Save Zulcom/66cd739de14fa787b6e4bfead8642862 to your computer and use it in GitHub Desktop.
С# - есть ли в данном слове заданная подстрока
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