Hi,

I want to convert a string to numbers ... i tried a lot of codes.. iam a beginner...

Kindly help...

Ex:

a=1 b=2 c=3 d=4 e=5 f=6 g=7 h=8 i=9 j=10

input value -->abc output value --> 123

input value -->abcj output value -->12310

I mean i want to output the alphabet position of the string to the numbers


Also, i want to have a html page GUI to input the value and get the output

Thanks

Does this help?

>>> import string
>>> dd = dict(zip(string.ascii_lowercase, [str(i) for i in range(1,27)]))
>>> "".join([dd[s] for s in "abcdejz"])
'123451026'
>>>

Looks familiar, I posted to similar question earlier in Stackoverflow:

base = ord('A') - 1
mystring = 'ABC'
print sum(ord(char) - base for char in mystring)

That has best score, but is not accepted answer in
http://stackoverflow.com/questions/3711303/how-do-i-assign-a-numerical-value-to-each-uppercase-letter

That can adapt to simply joining the letters also:

base = ord('a')-1
for mystring in ('ABC','abcj'):
    print ''.join(str(ord(char.lower()) - base) for char in mystring)

Yes...THats wat i want.. thanks guys..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.