String list and String set : Generic Collections « Generics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Generics » Generic CollectionsScreenshots 
String list and String set
   
#region License

/* **********************************************************************************
 * Copyright (c) Roman Ivantsov
 * This source code is subject to terms and conditions of the MIT License
 * for Irony. A copy of the license can be found in the License.txt file
 * at the root of this distribution. 
 * By using this source code in any fashion, you are agreeing to be bound by the terms of the 
 * MIT License.
 * You must not remove this notice from this software.
 * **********************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Irony.Parsing {

  public static class Strings {
    public const string AllLatinLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    public const string DecimalDigits = "1234567890";
    public const string OctalDigits = "12345670";
    public const string HexDigits = "1234567890aAbBcCdDeEfF";
    public const string BinaryDigits = "01";

    public static string JoinStrings(string separator, IEnumerable<string> values) {
      StringList list = new StringList();
      list.AddRange(values);
      string[] arr = new string[list.Count];
      list.CopyTo(arr, 0);
      return string.Join(separator, arr);
    }

  }//class

  public class StringDictionary : Dictionary<string, string> { }
  public class CharList : List<char{ }
  public class CharHashSet : HashSet<char{ } //adding Hash to the name to avoid confusion with System.Runtime.Interoperability.CharSet

  public class StringSet : HashSet<string> {
    public StringSet() { }
    public StringSet(StringComparer comparer: base(comparer) { }
    public override string ToString() {
      return ToString(" ");
    }
    public void AddRange(params string[] items) {
      base.UnionWith(items)
    }
    public string ToString(string separator) {
      return Strings.JoinStrings(separator, this);
    }
  }

  public class StringList : List<string> {
    public StringList() { }
    public StringList(params string[] args) {
      AddRange(args);
    }
    public override string ToString() {
      return ToString(" ");
    }
    public string ToString(string separator) {
      return Strings.JoinStrings(separator, this);
    }
    //Used in sorting suffixes and prefixes; longer strings must come first in sort order
    public static int LongerFirst(string x, string y) {
      try {//in case any of them is null
        if (x.Length > y.Lengthreturn -1;
      catch { }
      if (x == yreturn 0;
      return 1
    }

  }//class


}

   
    
    
  
Related examples in the same category
1.Generic Collection and List
2.Add user-defined object to generic Collection
3.Add Collection Items with IComparable interface implementation
4.Sort by Name
5.Add object in a hierarchy into a generic Collection
6.Generic collection class
7.Represents a generic collection of key/value pairs. The enumerator returns the values in the order assigned.
8.List To String
9.Convert Dictionary to String
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.