Func<string, string> RemoveDuplicate = delegate(string s)
{
BitArray _arr = new BitArray(256);
StringBuilder _sb = new StringBuilder();
s = s.ToLower();
for (int i = 0; i < s.Length; i++)
{
if (_arr[(int)s[i]])
{
continue;
}
else
{
_arr[(int)s[i]] = true;
_sb.Append(s[i]);
}
}
return _sb.ToString();
};
Func<string, string> ReverseString = delegate(string s)
{
char[] word = s.ToCharArray();
for (int i = 0, j = (s.Length - 1); i < j; i++, j--)
{
char _temp = word[i];
word[i] = s[j];
word[j] = _temp;
}
return new string(word);
};
string strCheck = '';
bool checkString = String.IsNullOrEmpty(strText);
string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };
IEnumerable<string> query =
Enumerable.Select (
Enumerable.OrderBy (
Enumerable.Where (
names, n => n.Contains ("a")
), n => n.Length
), n => n.ToUpper()
);
string strReverse ="";
string straoriginal = "Test";
if ((string.Compare(strOriginal, strReverse , false)) < 0)
{
MessageBox.Show("Less");
}
else if ((string.Compare(strOriginal, strReverse , false)) > 0)
{
MessageBox.Show("Greater");
}
else if ((string.Compare(strOriginal, strReverse , false)) == 0)
{
MessageBox.Show("Equal");
}
string strReverse ="";
string straoriginal = "Test";
string strReverse= Microsoft.VisualBasic.Strings.StrReverse(strOriginal);
MessageBox.Show(strReverse);
Progessive form
IEnumerable<string> filtered = names.Where (n => n.Contains ("a"));
IEnumerable<string> sorted = filtered.OrderBy (n => n.Length);
IEnumerable<string> finalQuery = sorted.Select (n => n.ToUpper());
Output
Harry
Mary
Jay
Jay
Mary
Harry
JAY
MARY
HARRY
string string1= "Split function";
string [] SplitString = string1.Split(new Char [] {' '});
MessageBox.Show(Convert.ToString(SplitString [0]));
MessageBox.Show(Convert.ToString(SplitString [1]));
Fluent query - LINQ
string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };
IEnumerable<string> query = names
.Where (n => n.Contains ("a"))
.OrderBy (n => n.Length)
.Select (n => n.ToUpper());
Simple Filter Query
from n in new[] { "Tom", "Dick", "Harry" }
where n.Contains ("a")
select n
Ouput: Harry
string string1 = "Replace string";
string finalstring= string1 .Replace("replace", "Replaced");
MessageBox.Show("Final Value : " + finalstring);
Extension method
(new[] {"T", "D", "H"} ).Where (n => n.Length >= 4)
string string1= "This is a substring function";
string search= "sub";
int charFirst= string1.IndexOf(search);
MessageBox.Show("String at : " + charFirst);
// description of your code here
string[] names = { "T", "D", "H" };
IEnumerable<string> filteredNames =
System.Linq.Enumerable.Where (names, n => n.Length >= 4);
foreach (string n in filteredNames)
Console.Write (n + "|");code>
int[] listA= { 1,2,3};
int[] ListB = { 1,5,6,4};
var result = listA.Except(listB);
foreach (var n in result)
{
Console.WriteLine(n);
}