OK so I have a string that has this:
Dan|warrior|54
I'm trying to make so I can use python and split it using |
as the delimiter. Here's what I have so far:
#!/usr/bin/env python dan = 'dan|warrior|54' print dan.split('|')
and that results into this:
['dan', 'warrior', '54']
I know it's incomplete but what do I have to do to finish it? Yes, I tried googling this problem... but it's not happening. :(
I want so that I can choose specifically which one from the delimiter so if I was dan.split('|')[1]
.. it would pick warrior
. See my point?
You can use the split() method of String class from JDK to split a String based on a delimiter e.g. splitting a comma-separated String on a comma, breaking a pipe-delimited String on a pipe, or splitting a pipe-delimited String on a pipe.
Python has a built-in method you can apply to string, called . split() , which allows you to split a string by a certain delimiter.
So, your input is 'dan|warrior|54' and you want "warrior". You do this like so:
>>> dan = 'dan|warrior|54' >>> dan.split('|')[1] "warrior"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With