Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Simple String Conversion?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary - 15 Feb 2006 12:07 GMT
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.
Hans Kesting - 15 Feb 2006 12:22 GMT
> Hello,
>
[quoted text clipped - 23 lines]
>
> 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
Karl Seguin [MVP] - 15 Feb 2006 12:32 GMT
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

Signature

http://www.openmymind.net/

> Hello,
>
[quoted text clipped - 23 lines]
>
> Gary.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.