How to convert string in ABCD format in to Unique integer

hi

Is there any way to convert string in this format ABCD into a unique integer like 1234

Example:

GWRS = 5232
SRWG = 7845
WTMS = 15
YOMS = 142

int X = ConvertMyString("GWRS");

private int ConvertMyString(string sTring)
{

}

and so on ......


Answer this question

How to convert string in ABCD format in to Unique integer

  • Jkumar

    You are right, I skipped the method name.

    int n = BitConverter.ToInt32 (Encoding.ASCII.GetBytes ("ABCD"), 0);

    Sorry.

    --mc


  • MaggieChan

    You might want to take a look at the GetHashCode method. It might do what you're looking for.

  • SCarmeli

    If it's always a 4-letter code and you don't care about getting large numbers, you could do something like:

    int n = BitConverter (Encoding.ASCII.GetBytes ("ABCD"), 0);

    HTH
    --mc


  • Balsoft

    Thanks ...

    I don't care about getting large numbers.

    But there is an error in your code

    Error 1 'System.BitConverter' is a 'type' but is used like a 'variable'


  • PatrickDonohue

    I'm sure there is, but you are going to have to better define the parameters of this conversion.

    Basically, tell me how you'd do it on paper, and I'll tell you how to do it on a computer.



  • How to convert string in ABCD format in to Unique integer