Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Simple String Conversion?

Reply
Thread Tools

Simple String Conversion?

 
 
Gary
Guest
Posts: n/a
 
      02-15-2006
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.


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      02-15-2006
> 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


 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      02-15-2006
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" <(E-Mail Removed)> wrote in message
news:3QEIf.4714$(E-Mail Removed).. .
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple error : method format(String, Object[]) is not applicable for the arguments (String, String) ankur Java 1 08-27-2007 06:31 AM
A simple 'Replace' and 'Substring' question: How to add a string to another string SM Javascript 4 04-27-2007 07:22 AM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments