PDA

View Full Version : Converting a character to a number


jassel41
02-08-2010, 08:40 PM
I am currently trying to figure out how to retrieve a character from a text file and turn it to a number.

I currently split up the sentence and store the word I am interested in into an array, for example a spot in the array may look like the following:

['Interval=4;']

What I want to do is access the 4 and save its numeric value to a variable. If this is stored in array[1] for example, is there a way to access the 10th character, (the 4) and then convert it to a number?

Thank you,
Jassel41

JvdBosch
02-10-2010, 07:37 AM
string = 'Interval=4'

string.split('=')[1] will return 4 (as string)
int(string.split('=')[1]) will return 4 (as int)
string[9] will return 4 (as string)
int(string[9]) will return 4 (as int)

And so on. Good luck!