• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

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

0
Rajar Ahmed
Asked:
Rajar Ahmed
  • 6
  • 4
1 Solution
 
Paul MacDonaldDirector, Information SystemsCommented:
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
 
Paul MacDonaldDirector, Information SystemsCommented:
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
 
Rajar AhmedConsultantAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Paul MacDonaldDirector, Information SystemsCommented:
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
 
Rajar AhmedConsultantAuthor Commented:
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  ?
0
 
Paul MacDonaldDirector, Information SystemsCommented:
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
 
Rajar AhmedConsultantAuthor Commented:
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

0
 
Paul MacDonaldDirector, Information SystemsCommented:
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
 
Paul MacDonaldDirector, Information SystemsCommented:
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
 
Rajar AhmedConsultantAuthor Commented:
thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now