Write a function that checks whether a string contains a giv
Solution
using System.IO;
using System;
class Program
{
static void Main()
{
Console.WriteLine(\"Enter the word: \");
string word=Console.ReadLine();
Console.WriteLine(\"Enter the substring: \");
string substring=Console.ReadLine();
bool result = ContainsSubstringIgnoreNumbers(word, substring);
if(result){
Console.WriteLine(\"The substring is present in string\");
}
else{
Console.WriteLine(\"The substring is not in the string\");
}
}
static bool ContainsSubstringIgnoreNumbers(string word, string substring){
int k=0;
for(int i=0; i<substring.Length ; i++){
for(int j=k; i<word.Length ; j++){
if(word[j] >= \'a\' && word[j] <= \'z\'){
if(substring[i] != word[j]){
return false;
}
else{
k=j+1;
break;
}
}
}
}
return true;
}
}
Output:
sh-4.3$ mcs *.cs -out:main.exe
sh-4.3$ mono main.exe
Enter the word:
1hom512e92
Enter the substring:
home
The substring is present in string
sh-4.3$ mono main.exe
Enter the word:
im3ag78i3e
Enter the substring:
image
The substring is not in the string

