International Text


   
 
/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Wrox.ProgrammingWindowsGUI.Chapter5
{
   /// <summary>
   /// Summary description for Form1.
   /// </summary>
   public class InternationalText : System.Windows.Forms.Form
   {
      internal System.Windows.Forms.Label lblInternationalText;
      internal System.Windows.Forms.Label lblCharCode;
      private System.Windows.Forms.TextBox textBox1;
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;

      public InternationalText()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();

         //
         // TODO: Add any constructor code after InitializeComponent call
         //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null) 
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

        #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.lblInternationalText = new System.Windows.Forms.Label();
         this.lblCharCode = new System.Windows.Forms.Label();
         this.textBox1 = new System.Windows.Forms.TextBox();
         this.SuspendLayout();
         // 
         // lblInternationalText
         // 
         this.lblInternationalText.Location = new System.Drawing.Point(8, 64);
         this.lblInternationalText.Name = "lblInternationalText";
         this.lblInternationalText.Size = new System.Drawing.Size(288, 23);
         this.lblInternationalText.TabIndex = 0;
         // 
         // lblCharCode
         // 
         this.lblCharCode.Location = new System.Drawing.Point(8, 96);
         this.lblCharCode.Name = "lblCharCode";
         this.lblCharCode.Size = new System.Drawing.Size(88, 23);
         this.lblCharCode.TabIndex = 2;
         // 
         // textBox1
         // 
         this.textBox1.Location = new System.Drawing.Point(8, 24);
         this.textBox1.Name = "textBox1";
         this.textBox1.Size = new System.Drawing.Size(288, 20);
         this.textBox1.TabIndex = 3;
         this.textBox1.Text = "";
         this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
         // 
         // InternationalText
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(304, 134);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.textBox1,
                                                                      this.lblCharCode,
                                                                      this.lblInternationalText});
         this.MaximizeBox = false;
         this.Name = "InternationalText";
         this.Text = "InternationalText";
         this.ResumeLayout(false);

      }
        #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main() 
      {
         Application.Run(new InternationalText());
      }

      protected override void OnInputLanguageChanged(InputLanguageChangedEventArgs e)
      {
         MessageBox.Show(e.InputLanguage.Culture.Name); 
      }

      protected override void OnInputLanguageChanging(InputLanguageChangingEventArgs e)
      {
         MessageBox.Show(e.InputLanguage.Culture.Name);
      }

      private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
      {
         lblInternationalText.Text += e.KeyChar.ToString();
         lblCharCode.Text = ((int)e.KeyChar).ToString();
      }
   }
}

           
         
     


Get the Hash code for string value

using System;
public class HashValues {
public static void Main( ) {
String[] identifiers ={“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”};

for(int i = 0; i < identifiers.Length; i++) { String id = identifiers[i]; int hash = id.GetHashCode(); int code = hash % 23; Console.WriteLine("{0,-12}{1,12}{2,12}", id, hash, code); } } } [/csharp]

Class behaves properly using overridden Equals and GetHashCode methods


   


using System;
using System.Collections;

public class GoodCompare {
  public static void Main() {
    Name president = new Name ("A", "B");
    Name first = new Name ("C", "D");
    Console.WriteLine("The hash codes for first and president are: ");
    
    if (president.GetHashCode() == first.GetHashCode())
       Console.WriteLine("equal");
    else
       Console.WriteLine("not equal");
    
  }
}



public class Name {
  protected String first;
  protected char initial;
  protected String last;
          
  public Name(String f, String l) {
    first = f; 
    last = l; 
  }
  public Name(String f, char i, String l) : this(f,l) {
    initial = i;  
  } 
  public override String ToString() {
    if (initial == &#039;u0000&#039;)
       return first + " " + last;
    else  
       return first + " " + initial + " " + last;
  }
  public override bool Equals(Object o) {
    if (!(o is Name))
       return false;
    Name name = (Name)o;
    return first == name.first &amp;&amp; initial == name.initial
             &amp;&amp; last == name.last;
  }
  public override int GetHashCode() {
    return first.GetHashCode() + (int)initial 
                             + last.GetHashCode();
  }

}


           
          


Converts the string representation of a Guid toits Guid equivalent.

   
 

//The MIT License (MIT)
//http://arolibraries.codeplex.com/license
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AroLibraries.ExtensionMethods.Strings
{
    public static class StringExt
    {
        /// <summary> Converts the string representation of a Guid toits Guid 
        ///  equivalent. A return value indicates whether the operation succeeded. 
        /// </summary> 
        /// <param name="s">A string containing a Guid to convert.</param> 
        /// <param name="result"> /// When this method returns, contains the Guid value equivalent to /// the Guid contained in <paramref name="s"/>, if the conversion  succeeded, or <see cref="Guid.Empty"/> if theconversion failed. /// The conversion fails if the 
        /// <paramref name="s"/> parameter is a /// <see langword="null" /> reference (<see langword="Nothing" /> in /// Visual Basic), or is not of the correct format.
        /// </param> ///
        /// <value> /// <see langword="true" /> if <paramref name="s"/> was converted /// successfully; otherwise, <see langword="false" />.  </value> 
        /// <exception cref="ArgumentNullException"> /// Thrown if <pararef name="s"/> is <see langword="null"/>. /// </exception>  
        /// <remarks> /// Original code at https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94072&amp;wa=wsignin1.0#tabs  </remarks> 
        public static bool Ext_IsValidGuid(this string s)
        {
            if (s == null)
                throw new ArgumentNullException("s");
            Regex format = new Regex("^[A-Fa-f0-9]{32}$|" +
                "^({|()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|))?$|" +
                "^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2},{0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$");
            Match match = format.Match(s);
            return match.Success;
        }
    }
}