Reverse a string in C#


using System;
using System.Data;
using System.Collections;
using System.Linq;
using System.Text;

public class checkString
{
public static void Main()
{
string strSource = "ABCacd12";

ReverseString(strSource);
}

public static void ReverseAString(string str)
{
int counter =0;
counter=str.Length;
StringBuilder strReversed = new StringBuilder();
while(counter!=0)
{
counter--;
strReversed.Append(str.ElementAt(counter));
}
Console.WriteLine(strReversed.ToString());
}
}
Advertisements

Finding if a string contains all unique characters.

I have used C# for this code snippet.


public class checkString
{
public static void Main()
{
string strSource = "ABCacd12";
if(CheckString1(strSource))
{
Console.WriteLine("Unique!!!");
}
else
{
Console.WriteLine("Not Unique!!!");
}
}

public static bool CheckString1(string str)
{
int strLength = str.Length;
for(int i=0;i<strLength;i++)
{
for(int j=i+1;j<strLength;j++)
{
if(str.ElementAt(i)==str.ElementAt(j)) return false;
}
}
return true;
}

}