0

I have the following text from a text file.

#AAA#WantedData#bbb#ccc#ddd#eee#SoOn#

I want to get only the WantedData from the above string. Always I want to get the data between second and third #sign.

What is the efficient way to achieve this in python?

1 Answer 1

1

Python String split() Method

The split() method splits a string into a list.

You can specify the separator, default separator is any whitespace.

data.split("#") # ['', 'AAA', 'WantedData', 'bbb', 'ccc', 'ddd', 'eee', 'SoOn', '']

you can do it just like this(if you always want data between second and third #sign.):

data = "#AAA#WantedData#bbb#ccc#ddd#eee#SoOn#"
print (data.split("#")[2])

output:

WantedData
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you! It looks easier than expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.