Link to home
Start Free TrialLog in
Avatar of Rajar Ahmed
Rajar AhmedFlag for India

asked on

get alphanumeric using number

the below code , returns integer only , but i need alphanumeric
like aB12C2 with lowercase n uppercase mixed .

Following this url ..
http://www.eggheadcafe.com/articles/20040331.asp
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)

Open in new window

Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

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.
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).

Avatar of Rajar Ahmed

ASKER

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.

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?
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,
http://www.eggheadcafe.com/articles/20040331.asp

this logic is used for checking captcha image text .
but all i want is alpha numeric code in that particular image  ?
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.
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

Open in new window

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.
ASKER CERTIFIED SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks.