Introduction
In this blog, we will study how we can find the repeated first character in the given string.
Given below code snippet will help you to understand how we can find the repeated first character in the given string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpAdvanncedProgramming
{
public static class FindRepeatFirst
{
public static int FindRepeatFirstInString(string Input)
{
int p = -1, i, j;
for ( i = 0; i < Input.Length; i++)
{
for (j=i+1; j < Input.Length; j++)
{
if (Input[i] == Input[j])
{
p= i;
break;
}
}
if (p!=-1)
{
break;
}
}
return p;
}
}
}
Main Class Code
using CSharpAdvanncedProgramming;
string Input = "Mudassar Ali";
int Output = FindRepeatFirst.FindRepeatFirstInString(Input);
if (Output==-1)
{
Console.WriteLine("Not Found");
}
else
{
Console.WriteLine("First Repeated Values is :"+ Input[Output]);
}
Program Output