c# coding simple  question 

 

1.To find total number of occurrence of a character or string .

2. how to reverse a string .

3. Find Even odd.

 

I am writing the method that you can call .

public static int CountStringOccurrences(string text, string pattern)
{
int count = 0;
int i = 0;
while ((i = text.IndexOf(pattern, i)) != -1)
{
i += pattern.Length;
count++;
}
return count;
}

 

 

 
public static string Reverse(string s1)
{
string s2 = “”;
int Length = s1.Length-1;
while (Length >= 0)
s2 = s2 + s1[Length–];
return s2;
}

 

 

 
public static bool evenOdd(int i)
{
if (i % 2 == 0) return true; else return false;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s