Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Kérem a mintát.");
- String Base = Console.ReadLine();
- Console.WriteLine("Kérem a keresendő szöveget belőle.");
- String SearchFor = Console.ReadLine();
- int Hoooh = ImAnIdiot(SearchFor, Base);
- if (Hoooh != -1)
- {
- Console.WriteLine("A keresett szöveg a " + (Hoooh + 1) + ". helyen kezdődött.");
- } else {
- Console.WriteLine("A keresett szöveg nem volt benne a sorban.");
- }
- }
- static int ImAnIdiot(string SearchFor, string SearchIn)
- {
- for (int i = 0; i < SearchIn.Length; i++)
- {
- if (SearchIn[i] == SearchFor[0]) {
- for (int j = i, k = 0; k < SearchFor.Length; j++, k++)
- {
- if (SearchIn[j] != SearchFor[k])
- {
- break;
- }
- if (k == SearchFor.Length - 1)
- {
- return i;
- }
- }
- }
- }
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement