Click here to Skip to main content
15,886,422 members
Home / Discussions / C#
   

C#

 
GeneralRe: Design Patterns - on a mission. Pin
Jim Stewart4-Sep-03 3:27
Jim Stewart4-Sep-03 3:27 
GeneralOleDbException: Multiple-step OLE DB operation generated errors. Pin
mikemilano3-Sep-03 6:41
mikemilano3-Sep-03 6:41 
GeneralVB script to C# Pin
Majid Shahabfar3-Sep-03 4:35
Majid Shahabfar3-Sep-03 4:35 
GeneralRe: VB script to C# Pin
Alvaro Mendez3-Sep-03 6:29
Alvaro Mendez3-Sep-03 6:29 
GeneralRe: VB script to C# Pin
Majid Shahabfar3-Sep-03 19:03
Majid Shahabfar3-Sep-03 19:03 
GeneralRe: VB script to C# Pin
Corinna John4-Sep-03 2:00
Corinna John4-Sep-03 2:00 
GeneralRe: VB script to C# Pin
Majid Shahabfar6-Sep-03 3:42
Majid Shahabfar6-Sep-03 3:42 
GeneralRe: VB script to C# Pin
Richard Deeming5-Sep-03 8:05
mveRichard Deeming5-Sep-03 8:05 
The AscW and ChrW functions are directly equivalent to casting between a char and an int;

To correctly duplicate the Chr and Asc functions needs a bit more work. You could add a reference to the Microsoft.VisualBasic assembly, and use the static methods of the Strings class. Alternatively, you can use:
C#
public static char Chr(int i) 
{
    if (0 <= i && i <= 127) return (char)i;
    if (i < -0x8000 || i > 0xFFFF) throw new ArgumentOutOfRangeException();
    
    System.Text.Encoding enc = System.Text.Encoding.Default;
    if (enc.GetMaxByteCount(1) == 1 && (i < 0 || i > 0xFF)) 
        throw new ArgumentOutOfRangeException();
    
    System.Text.Decoder dec = enc.GetDecoder();
    byte[] b;
    char[] c;
    if (0 <= i && i <= 0xFF) 
    {
        b = new byte[1];
        b[0] = checked((byte) (i & 0xFF));
        c = new char[1];
        dec.GetChars(b, 0, 1, c, 0);
    }
    else 
    {
        b = new byte[2];
        b[0] = checked((byte) ((i >> 8) & 0xFF));
        b[1] = checked((byte) (i & 0xFF));
        c = new char[1];
        dec.GetChars(b, 0, 2, c, 0);
    }
    return c[0];
}
 
public static int Asc(char ch) 
{
    int i = (int)ch;
    if (i < 128) return i;
    
    System.Text.Encoding enc = System.Text.Encoding.Default;
    char[] c = new char[] {ch};
    byte[] b = enc.GetBytes(c);
    if (b.Length == 2 && BitConverter.IsLittleEndian) 
    {
        byte t = b[0];
        b[0] = b[1];
        b[1] = t;
    }
    if (b.Length == 2)
        return BitConverter.ToInt16(b,0);
    else
        return b[0];
}



"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
GeneralRe: VB script to C# Pin
Majid Shahabfar6-Sep-03 3:43
Majid Shahabfar6-Sep-03 3:43 
GeneralRe: VB script to C# Pin
dog_spawn3-Sep-03 7:04
dog_spawn3-Sep-03 7:04 
QuestionRSA public key? Pin
ravingcoder3-Sep-03 4:05
ravingcoder3-Sep-03 4:05 
AnswerRe: RSA public key? Pin
ravingcoder3-Sep-03 17:12
ravingcoder3-Sep-03 17:12 
QuestionHow can we prevent a C++ Class from inheritance? Pin
sri sankaradoss3-Sep-03 1:59
sri sankaradoss3-Sep-03 1:59 
AnswerRe: How can we prevent a C++ Class from inheritance? Pin
Alvaro Mendez3-Sep-03 6:24
Alvaro Mendez3-Sep-03 6:24 
Generalruntime references Pin
wrzeszcz3-Sep-03 1:36
wrzeszcz3-Sep-03 1:36 
QuestionHow to pass an object to an exe Pin
Member 486393-Sep-03 1:08
Member 486393-Sep-03 1:08 
AnswerRe: How to pass an object to an exe Pin
dog_spawn3-Sep-03 1:34
dog_spawn3-Sep-03 1:34 
AnswerRe: How to pass an object to an exe Pin
Daniel Turini3-Sep-03 1:58
Daniel Turini3-Sep-03 1:58 
GeneralGetHashCode() Pin
deanoA3-Sep-03 0:18
deanoA3-Sep-03 0:18 
GeneralRe: GetHashCode() Pin
dog_spawn3-Sep-03 1:31
dog_spawn3-Sep-03 1:31 
GeneralRe: GetHashCode() Pin
freshthinking3-Sep-03 4:42
freshthinking3-Sep-03 4:42 
GeneralRe: GetHashCode() Pin
James T. Johnson3-Sep-03 6:54
James T. Johnson3-Sep-03 6:54 
GeneralRe: GetHashCode() Pin
dog_spawn3-Sep-03 7:06
dog_spawn3-Sep-03 7:06 
GeneralRe: GetHashCode() Pin
James T. Johnson3-Sep-03 7:09
James T. Johnson3-Sep-03 7:09 
GeneralRe: GetHashCode() Pin
--daljv--3-Sep-03 16:17
suss--daljv--3-Sep-03 16:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.