Extract a substring from a string based on the position of character - Python
Im trying to extract the substrings from the below string
package: name='com.example.tracker' versionCode='1' versionName='1.0'
as string 1 : versionCode='1' and as string 2: versionName='1.0'
I used str.find('versionCode) which returns me the index of 'v' in the
versioncode and i used string length to access '1'. However there are time
the versioncode might be a double digit number so I can't fix the location
of the digit. Is there a way to achieve this?
If the string is
package: name='com.example.tracker' versionCode='12' versionName='12.0'
I need to extract 12 and 12.0. My implementation can support single digits
but the digits will vary.
if line.find('versionCode') != -1:
x = line.find('versionCode')
versionCode = line[x+13:x+15]
No comments:
Post a Comment