Snippets
Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!

Snippets

  • Tweet
  • spacer
DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
spacer

Recent Snippets

  • String
  • zero
  • null
  • .net
  • length

Check If String Is Null / Zero Length

05/07/12 by Snippets Manager
                    
string strCheck = '';
bool checkString = String.IsNullOrEmpty(strText);
                
0 Replies
  • method
  • shunning
  • extension

Shunning Extension Method To Filter Order And Sort- Linq

05/07/12 by Snippets Manager
                    
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()
  );
  
                
0 Replies
  • String
  • compare
  • two

Comapre Two Strings

05/07/12 by Snippets Manager
                    
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");
    }
                
0 Replies
  • reverse
  • csharp
  • .net
  • String

Reverse A String

05/07/12 by Snippets Manager in C#
                    
string strReverse ="";
string straoriginal = "Test";
string strReverse= Microsoft.VisualBasic.Strings.StrReverse(strOriginal);
    MessageBox.Show(strReverse); 
                
0 Replies
  • LINQ
  • sorting
  • order
  • filter

Progressive Query - LINQ

05/07/12 by Snippets Manager
                    
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
 
 
 

 
 

                
0 Replies
  • .net
  • split
  • function
  • String

Splitting A String Using String Function

05/07/12 by Snippets Manager
                    
string string1= "Split function";
string [] SplitString = string1.Split(new Char [] {' '});
MessageBox.Show(Convert.ToString(SplitString [0]));
MessageBox.Show(Convert.ToString(SplitString [1])); 
                
0 Replies
  • fluent
  • LINQ
  • query

Fluent Query - LINQ

05/07/12 by Snippets Manager
                    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());
                
0 Replies
  • filter
  • LINQ
  • query
  • Simple

Simple Filter Query - LINQ

05/07/12 by Snippets Manager
                    Simple Filter Query 
from n in new[] { "Tom", "Dick", "Harry" }
where n.Contains ("a")
select n

Ouput: Harry                
0 Replies
  • String
  • .net
  • function
  • replace

Replace String With In String

05/07/12 by Snippets Manager
                    
string string1 = "Replace string";
string finalstring= string1 .Replace("replace", "Replaced");
MessageBox.Show("Final Value : " + finalstring); 
                
0 Replies
  • LINQ
  • extension
  • method

Filter Using Extension Method - LINQ

05/07/12 by Snippets Manager
                    Extension method

(new[] {"T", "D", "H"} ).Where (n => n.Length >= 4)
                
0 Replies
  • 1
  • 2
  • 3
  • 4
  • >
  • >>