Write a function that checks whether a string contains a giv

Write a function that checks whether a string contains a given substring. The function should ignore all numbers. String: 1hom512e92w1rk Substring: home The substring is present in the string! String: im2agline Substring: image The substring is not in the string static bool ContainsSubstringIgnoreNumbers (string word, string substring)

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

 Write a function that checks whether a string contains a given substring. The function should ignore all numbers. String: 1hom512e92w1rk Substring: home The su
 Write a function that checks whether a string contains a given substring. The function should ignore all numbers. String: 1hom512e92w1rk Substring: home The su

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site