Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
System.Environment.NewLine

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • *Experts*
Posted
You could use ControlChars.Tab, but the ControlChars class is VB-specific and I wouldn't reccomend it. You can also use Convert.ToChar(9), since 9 is the Unicode value for a tab character.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted (edited)

As I can never remember the codes for keys, I like -

(char) Keys.Tab

 

or in either this will work, too:

Convert.ToChar(Keys.Tab)

 

Too bad "Keys.Tab.ToString()" doesn't return the tab character, eh?

 

hmmmm. . . . give me a moment. . . .

Edited by Joe Mamma

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted (edited)

probably easier to do with CodeDom, but I have never used it. . .

 

to generate a class with usage:

char c = Unicode.Chars.Tab;
string c = Unicode.Chars.Tab.ToString();

 

executing this line:

Unicode.GenClass.Chars.GenClass();

on this class:

 

using System;

 

namespace Unicode.GenClass

{

 

public sealed class Chars

{

private Chars() {}

 

static void EnumProperty(string aKey)

{

 

object testKey = Enum.Parse(typeof(System.Windows.Forms.Keys), aKey);

if ( (Convert.ToInt32(testKey)> UInt16.MaxValue) | Convert.ToInt32(testKey) < 0) return;

Console.WriteLine("");

string keyName = aKey;

string keytype = string.Format("System.Windows.Forms.Keys.{0}", keyName);

Console.WriteLine(string.Format("\t\tstatic public char {0}", keyName));

Console.WriteLine("\t\t{");

Console.WriteLine("\t\t\tget");

Console.WriteLine("\t\t\t{");

Console.WriteLine(string.Format("\t\t\t\t return(char){0};", keytype));

Console.WriteLine("\t\t\t}");

Console.WriteLine("\t\t}");

}

 

public static void GenClass()

{

Console.WriteLine("using System;");

Console.WriteLine("");

Console.WriteLine("namespace Unicode");

Console.WriteLine("{");

Console.WriteLine("\tpublic sealed class Chars");

Console.WriteLine("\t{");

Console.WriteLine("");

Console.WriteLine("\t\tprivate Chars(){}");

foreach (string akey in Enum.GetNames(typeof(System.Windows.Forms.Keys)))

EnumProperty(akey);

Console.WriteLine("\t}");

Console.WriteLine("}");

}

}

}

[/CS]

 

genrated the attached source to the console window

Unicode.Chars.zip

Edited by Joe Mamma

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted
I am sure the above would be easier and more elegant with CodeDOM, but I have never played with it. . .

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

the first handful of properties generated as the code is too long to post. . .

using System;
namespace Unicode
{
public sealed class Chars
{

 private Chars(){}

 static public char None
 {
  get
  {
   return(char)System.Windows.Forms.Keys.None;
  }
 }

 static public char LButton
 {
  get
  {
   return(char)System.Windows.Forms.Keys.LButton;
  }
 }

 static public char RButton
 {
  get
  {
   return(char)System.Windows.Forms.Keys.RButton;
  }
 }

 static public char Cancel
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Cancel;
  }
 }

 static public char MButton
 {
  get
  {
   return(char)System.Windows.Forms.Keys.MButton;
  }
 }

 static public char XButton1
 {
  get
  {
   return(char)System.Windows.Forms.Keys.XButton1;
  }
 }

 static public char XButton2
 {
  get
  {
   return(char)System.Windows.Forms.Keys.XButton2;
  }
 }

 static public char Back
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Back;
  }
 }

 static public char Tab
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Tab;
  }
 }

 static public char LineFeed
 {
  get
  {
   return(char)System.Windows.Forms.Keys.LineFeed;
  }
 }

 static public char Clear
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Clear;
  }
 }

 static public char Return
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Return;
  }
 }

 static public char Enter
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Enter;
  }
 }

 static public char ShiftKey
 {
  get
  {
   return(char)System.Windows.Forms.Keys.ShiftKey;
  }
 }

 static public char ControlKey
 {
  get
  {
   return(char)System.Windows.Forms.Keys.ControlKey;
  }
 }

 static public char Menu
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Menu;
  }
 }

 static public char Pause
 {
  get
  {
   return(char)System.Windows.Forms.Keys.Pause;
  }
 }

 static public char CapsLock
 {
  get
  {
   return(char)System.Windows.Forms.Keys.CapsLock;
  }
 }

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • *Experts*
Posted

If everyone in your group agrees to it, you can just use "\t", as Joe sorta had embedded in one of his samples. I'd only do that if everyone knows and understands what \t is - if your group thinks that's too obscure, then don't use it.

 

I often use \n in strings for newline if they're embedded. I'll use Environment.NewLine for piecing strings together. For example:

string s = "You are about to delete your whole Database and format the hard drive.\n\nAre you sure?"
string s2 = "Bob" + Environment.NewLine;
s2 += "The" + Environment.NewLine;
s2 += "Builder";

 

Of course, I'd probably use StringBuilder in place of s2, but I don't want to type that out right now...

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

In working with something different, I came across the "ControlChars" object in the helpfile. If you type it and hit "." you'll find methods such as...

 

ControlChars.NewLine

ControlChars.CrLf

ControlChars.Tab

 

Along with a few others. (The first two above are the same thing.) Not sure if they are more or less preferred over System.Environment.NewLine, but thought I'd pass it on if others are interested at least in the .Tab, which I think is handy.

Posted

Just out of interest, here, are we talking VS.NET or ASP.NET?

 

I've just tried vbCrLf and it does convert...

 

Is this a good practice/bad practice thing? There seem to be so many of them...

 

 

Paul.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...