C# Sharp Exercises: Determine whether the string "birds" is a substring of a familiar
C# Sharp String: Exercise-38 with Solution
Write a C# Sharp program to determine whether the string "birds" is a substring of a familiar.
Note : Quotation ‘two birds with one stone'.
Sample Solution:-
C# Sharp Code:
using System;
class Example38
{
public static void Main()
{
string str1 = "Kill two birds with one stone";
string str2 = "birds";
bool x = str1.Contains(str2);
Console.WriteLine("'{0}' is in the string '{1}': {2}",
str2, str1, x);
if (x) {
int index = str1.IndexOf(str2);
if (index >= 0)
Console.WriteLine("'{0} begins at character position {1}",
str2, index + 1);
}
}
}
Sample Output:
'birds' is in the string 'Kill two birds with one stone': True 'birds begins at character position 10
Flowchart :
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to concatenate the array values of strings.
Next: Write a C# Sharp program to creates two string objects with different values. When it calls the Copy method to assign the first value to the second string, the output indicates that the strings represent different object references although their values are now equal. On the other hand, when the first string is assigned to the second string, the two strings have identical values because they represent the same object reference.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework