Simple String Conversion?

Discussion in 'ASP .Net Web Services' started by Gary, Feb 15, 2006.

  1. Gary

    Gary Guest

    Hello,

    I collect a string on my ASP.NET page via Request.QueryString.

    For Example:
    http://www.site.com/index.aspx?Outlook=BAD

    I now want to take this string and convert it to a NUMERICAL string based on
    the position within the alphabet.n Spaces OR Dashes between each character
    is important

    So,

    BAD becomes 2-1-4
    ADD becomes 1-4-4
    AZA becomes 1-26-1
    ABC becomes 1-2-3
    XYZ becomes 24-25-26

    Anyone got any ideas on how best to achieve this? The string needs to be
    generated before page load or as the first item on page load.

    Thanks for any help offered,

    Regards,

    Gary.
     
    Gary, Feb 15, 2006
    #1
    1. Advertising

  2. Gary

    Hans Kesting Guest

    > Hello,
    >
    > I collect a string on my ASP.NET page via Request.QueryString.
    >
    > For Example:
    > http://www.site.com/index.aspx?Outlook=BAD
    >
    > I now want to take this string and convert it to a NUMERICAL string based on
    > the position within the alphabet.n Spaces OR Dashes between each character
    > is important
    >
    > So,
    >
    > BAD becomes 2-1-4
    > ADD becomes 1-4-4
    > AZA becomes 1-26-1
    > ABC becomes 1-2-3
    > XYZ becomes 24-25-26
    >
    > Anyone got any ideas on how best to achieve this? The string needs to be
    > generated before page load or as the first item on page load.
    >
    > Thanks for any help offered,
    >
    > Regards,
    >
    > Gary.


    Loop through the characters in the input string,
    Find the position of the character in a "alphabet string" (" ABCD...")
    (Note: I added a space at the beginning, so 'A' is at position 1)
    Add a '-' plus that position to the output string (maybe use
    StringBuilder)
    Finally, forget the first character of that output (a '-')

    Hans Kesting
     
    Hans Kesting, Feb 15, 2006
    #2
    1. Advertising

  3. I question the design of whatever it is ur building. It seems
    unecessary...but...assuming you know more about what ur building than I do
    ;) try:

    int valueOfA = ((int)'A') - 1;
    char[] chars = input.ToCharArray();
    foreach (char c in chars)
    {
    int value = ((int)c) - valueOfA;
    //value is now the numeric value
    }

    Karl

    --
    http://www.openmymind.net/



    "Gary" <> wrote in message
    news:3QEIf.4714$...
    > Hello,
    >
    > I collect a string on my ASP.NET page via Request.QueryString.
    >
    > For Example:
    > http://www.site.com/index.aspx?Outlook=BAD
    >
    > I now want to take this string and convert it to a NUMERICAL string based
    > on the position within the alphabet.n Spaces OR Dashes between each
    > character is important
    >
    > So,
    >
    > BAD becomes 2-1-4
    > ADD becomes 1-4-4
    > AZA becomes 1-26-1
    > ABC becomes 1-2-3
    > XYZ becomes 24-25-26
    >
    > Anyone got any ideas on how best to achieve this? The string needs to be
    > generated before page load or as the first item on page load.
    >
    > Thanks for any help offered,
    >
    > Regards,
    >
    > Gary.
    >
     
    Karl Seguin [MVP], Feb 15, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary

    Simple String Conversion?

    Gary, Feb 15, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    443
    Karl Seguin [MVP]
    Feb 15, 2006
  2. Alexander Eisenhuth
    Replies:
    5
    Views:
    561
    Bob Gailer
    Jul 25, 2003
  3. Phillip Vong

    Simple Conversion from String to Date

    Phillip Vong, Dec 7, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,966
    Phillip Vong
    Dec 7, 2006
  4. ankur
    Replies:
    1
    Views:
    13,066
    Jan =?UTF-8?B?VGhvbcOk?=
    Aug 27, 2007
  5. , India
    Replies:
    2
    Views:
    510
    Fraser Ross
    Sep 15, 2009
Loading...

Share This Page