|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Input - String : Output - Binary Oct Dec Hexstring test = char(2) + "HelloWorld" + char(29); IsPrintableCharToDec(test[i]); My target: Example Output <2>HelloWorld<29> public string IsPrintableCharToDec(char c) { string ret= c.ToString(); if ((!char.IsLetterOrDigit(c) && !char.IsPunctuation(c)) && !char.IsSymbol(c)) { ret = "<" + c.ToString() + ">"; } return ret; } Output <2>HelloWorld<1D> public string IsPrintableCharToHex(char c) { string ret= c.ToString(); if ((!char.IsLetterOrDigit(c) && !char.IsPunctuation(c)) && !char.IsSymbol(c)) { ret = "<" + c.ToString() + ">"; } return ret; } http://en.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange Binary Oct Dec Hex Abbr PR[t 1] CS[t 2] CEC[t 3] Description 000 0000 000 0 00 NUL †^@ \0 Null character 000 0001 001 1 01 SOH â ^A Start of Header 000 0010 002 2 02 STX â‚ ^B Start of Text 000 0011 003 3 03 ETX ⃠^C End of Text How can I reach my goal? Greeting Markus Hello,
Try : http://msdn.microsoft.com/en-us/library/b1kwkfdz.aspx (assuming your problem is the converting to base 2, 8 or 16). -- Show quoteHide quotePatrice "Markus Sommer" <m*@Not.de> a écrit dans le message de groupe de discussion : u6WzJt#$JHA.4***@TK2MSFTNGP05.phx.gbl... > Hello! > > string test = char(2) + "HelloWorld" + char(29); > > IsPrintableCharToDec(test[i]); > > My target: > Example > Output <2>HelloWorld<29> > > public string IsPrintableCharToDec(char c) > { > string ret= c.ToString(); > if ((!char.IsLetterOrDigit(c) && > !char.IsPunctuation(c)) && > !char.IsSymbol(c)) > { > ret = "<" + c.ToString() + ">"; > } > return ret; > } > > > Output <2>HelloWorld<1D> > > public string IsPrintableCharToHex(char c) > { > string ret= c.ToString(); > if ((!char.IsLetterOrDigit(c) && > !char.IsPunctuation(c)) && > !char.IsSymbol(c)) > { > ret = "<" + c.ToString() + ">"; > } > return ret; > } > > http://en.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange > Binary Oct Dec Hex Abbr PR[t 1] CS[t 2] CEC[t 3] Description > 000 0000 000 0 00 NUL ? ^@ \0 Null character > 000 0001 001 1 01 SOH ? ^A Start of Header > 000 0010 002 2 02 STX ? ^B Start of Text > 000 0011 003 3 03 ETX ? ^C End of Text > > > How can I reach my goal? > > Greeting Markus Hello Patrice,
"Patrice" <http://scribe-en.blogspot.com/> schrieb im Newsbeitrag yes works well.news:enrXe6#$JHA.5780@TK2MSFTNGP03.phx.gbl... > Hello, > > Try : > http://msdn.microsoft.com/en-us/library/b1kwkfdz.aspx > > (assuming your problem is the converting to base 2, 8 or 16). Is that or know you another way? Maybe GetByteConverter? I'm not sure. Greeting Markus using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { class Program { public static string IsPrintableChar(char c) { string ret = c.ToString(); if ((!char.IsLetterOrDigit(c) && !char.IsPunctuation(c)) && !char.IsSymbol(c)) { char number2 = c; // (char)29; int baseValue2 = 10; Console.WriteLine(" {0,-8} --> 0x{1}", number2, Convert.ToString(number2, baseValue2)); ret = "<" + Convert.ToString(number2, baseValue2) + ">"; } return ret; } //http://msdn.microsoft.com/en-us/library/b1kwkfdz.aspx //http://msdn.microsoft.com/en-us/library/system.componentmodel.byteconverter.aspx static void Main(string[] args) { int[] bases = { 2, 8, 10, 16 }; short[] numbers = { Int16.MinValue, -13621, -18, 12, 19142, Int16.MaxValue }; foreach (int baseValue in bases) { Console.WriteLine("Base {0} conversion:", baseValue); foreach (short number in numbers) { Console.WriteLine(" {0,-8} --> 0x{1}", number, Convert.ToString(number, baseValue)); } } Console.WriteLine("IsPrintableChar {0}", IsPrintableChar((char)29)); Console.ReadKey(); } } } If it works stick to it.. This is a lower level infrastructure for type
conversion and I'm not even sure it supports using a base. -- Show quoteHide quotePatrice "Markus Sommer" <m*@Not.de> a écrit dans le message de groupe de discussion : #E0PzQLAKHA.3***@TK2MSFTNGP02.phx.gbl... > Hello Patrice, > > "Patrice" <http://scribe-en.blogspot.com/> schrieb im Newsbeitrag > news:enrXe6#$JHA.5780@TK2MSFTNGP03.phx.gbl... >> Hello, >> >> Try : >> http://msdn.microsoft.com/en-us/library/b1kwkfdz.aspx >> >> (assuming your problem is the converting to base 2, 8 or 16). > > yes works well. > Is that or know you another way? > > Maybe GetByteConverter? I'm not sure. > > Greeting Markus > > > using System; > using System.Collections.Generic; > using System.Linq; > using System.Text; > > namespace Test > { > class Program > { > public static string IsPrintableChar(char c) > { > string ret = c.ToString(); > if ((!char.IsLetterOrDigit(c) && > !char.IsPunctuation(c)) && > !char.IsSymbol(c)) > { > char number2 = c; // (char)29; > int baseValue2 = 10; > Console.WriteLine(" {0,-8} --> 0x{1}", number2, > Convert.ToString(number2, baseValue2)); > > ret = "<" + Convert.ToString(number2, baseValue2) + ">"; > } > return ret; > } > > //http://msdn.microsoft.com/en-us/library/b1kwkfdz.aspx > //http://msdn.microsoft.com/en-us/library/system.componentmodel.byteconverter.aspx > > static void Main(string[] args) > { > > int[] bases = { 2, 8, 10, 16 }; > short[] numbers = { Int16.MinValue, -13621, -18, 12, 19142, > Int16.MaxValue }; > > foreach (int baseValue in bases) > { > Console.WriteLine("Base {0} conversion:", baseValue); > foreach (short number in numbers) > { > Console.WriteLine(" {0,-8} --> 0x{1}", > number, Convert.ToString(number, > baseValue)); > } > } > > Console.WriteLine("IsPrintableChar {0}", > IsPrintableChar((char)29)); > Console.ReadKey(); > } > } > } > >
Other interesting topics
Replace strings in a text file and get the number of replacements made
Re: Ideas as to why file is locked Getting StandardIn has not been redirected when starting new Process Need advice on Class. Thank You Drag Drop - Move Data Between Apps How to use bring to front and Send to back so the rsult is good String Array to List Show application at Windows Vista Login/Locked screen "on-line" lex and yacc parser generators Changing the timeouts for WCF services |
|||||||||||||||||||||||