Solved

# get alphanumeric using number

Posted on 2011-10-12
274 Views
the below code , returns integer only , but i need alphanumeric
like aB12C2 with lowercase n uppercase mixed .

Following this url ..
``````Dim test As String = "12345"
Dim finalStr As String = ""
Dim y As Integer = 0
For i As Integer = 0 To test.Length - 1
y = Int32.Parse(test(i)) + 1a
finalStr += y.ToString()
Next
Response.Write(finalStr)
``````
0
Question by:Rajar Ahmed

LVL 33

Expert Comment

This is what's making it numeric:
y = Int32.Parse(test(i)) + 1a

You could replace that with something that generates valid ASCII characters, but you'd have to re-write it so the values you generated were all valid.
0

LVL 33

Expert Comment

In other words, you could write something where y is a random ASCII character value.  The numbers 0 through 9 are CHR(48) through CHR(57), upper case letters are CHR(65) though CHR(90), and lower case letters are CHR(97) through CHR(122).

0

LVL 18

Author Comment

i dont want to use random value .
now that
if,test  is 12345 the final value is 23456
Similarly  want to get
12345 the final value should b aB12C3
it should be constant always whenever test string is 12345.

0

LVL 33

Expert Comment

I'm not sure I get what you're after.  If the input is always aB12C3, you want the output to always be aB12C3?  If so, why convert it at all?

Or are you saying you want 12345 to always convert to aB12C3?

Do you understand what the original code is doing?
0

LVL 18

Author Comment

yes , i understand that
code is simple it jus add 1 with the test string loop
and returns final string as integer

Test string is 123456 - > while executing for Loop ->it gives  23456
Expected Result should be
123456 -> on for loop - > i want it as alphanumeric

if u see in this example,

this logic is used for checking captcha image text .
but all i want is alpha numeric code in that particular image  ?
0

LVL 33

Expert Comment

So, you want to increment the values by one?

You can try replacing
y = Int32.Parse(test(i)) + 1a
finalStr += y.ToString()

with something like
y = CHR(ASC(test(i) + 1)
finalStr += y

But you'll run into problems with input values of 9, Z, and z which will return :, [, and (, respectively.
0

LVL 18

Author Comment

input is always numeric .
i need output as alphanumeric ?
With output  Formatted like
aB12C3 (combination of lower case,upper case,numeric )

ur code dint worked
i change like below ,
y = AscW(Chr(Asc(test(i)))) + 1
but the result is same numeric
5856575554
``````For i As Integer = 0 To test.Length - 1
'y = Int32.Parse(test(i)) + 1
y = AscW(Chr(Asc(test(i)))) + 1
finalStr += y.ToString()
Next
``````
0

LVL 33

Expert Comment

Yeah, I didn't get a chance to test my code - I wrote it off the cuff.  The point was to convert the input string to and ASCII integer value, add 1, then convert back to an ASCII character.  I'll work on it in a bit and get back to you if you don't figure it out first.
0

LVL 33

Accepted Solution

Okay, I just hacked this out:

Dim test As String = "a1B2c3"
Dim y As String = Nothing
Dim finalstr As String = Nothing
For i As Integer = 0 To test.Length - 1
y = Chr(Asc(test(i)) + 1)
finalstr += y.ToString()
Next
Response.Write(finalstr & "<br />")

It takes "a1B2c3" and returns "b2C3d4"
0

LVL 18

Author Closing Comment

thanks.
0

## Featured Post

### Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!