63 064
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #15902 in C# for leena

Question #15902
write a prg that accepts 2 strings from the user. Also write code to print positions of all occurrences of the second string in the fisrt string using regular experssion.
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Occurrences_of_the_second_string_in_the_fisrt
{
class Program
{
static void Main(string[] args)
{
string firststring="";
string secondstring = "";
Console.Write("Enter first string: ");
firststring = Console.ReadLine();
Console.Write("Enter second string: ");
secondstring = Console.ReadLine();
Regex FindA = new Regex(secondstring);
int count = 0;
foreach (Match Tag in FindA.Matches(firststring))
{
Console.WriteLine("Found "+secondstring+" at {0}", Tag.Index);
count++;
if (count == 0) {
break;
}
}
if (count > 0) {
Console.WriteLine("Not found ");
}
Console.ReadLine();
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions