Convert string to byte array using ANSI

Posted on 2006-05-19
Last Modified: 2010-04-16

I have a string that was created using ANSI encoding (Created in Visual FoxPro) The string was encrypted using some math to replace the characters and when I convert the string into a char array in .NET i get different byte values. How can I convert a string into a byte array or char array using ANSI?

Thank you
Question by:irmsystems
    LVL 10

    Expert Comment

    try this methods.

    System.Text.ASCIIEncoding.ASCII.GetBytes() //to get the bytes
    System.Text.ASCIIEncoding.ASCII.GetString() //to get the string

    Author Comment

    Thanks I have tried that

    Here is an example that doesn't work

    My string that I need to get the bytes from:

    string sTest = "ŠŒ™‹‘•“œœž";

    The value of the S with the caron is 138 in FoxPro and in .NET it is 352

    .NET is using UNICODE to get the byte value. I need to somehow use ANSI within .NET to get the value of 138 for the character.


    Author Comment


    I got it figured out.  

    Byte[] encodedBytes = System.Text.Encoding.Default.GetBytes(sString);
    LVL 10

    Expert Comment

    thats nice.
    LVL 10

    Expert Comment

    dear netminder.

    I think irmsystems get the exact solution from my suggesstion.
    On his question he was not given the exact string / byte arry to check.
    so that only I post some methods in the Ascii encoding clssas.

    I dont want this kind of behavior from irmsystems

    go ahead Netminder . i dont want the points


    Accepted Solution

    Closed, 100 points refunded.

    The Experts Exchange
    Community Support Moderator of all Ages

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now