0

How would parse out a pipe delimited string in Python 3.0? My application is reading various barcodes in a random fashion. The barcodes are as below:

var = '07|415674|88881234564|3326'

I need to evaluate the length of each parsed variable and determine the one barcode I'm looking for.

Thanks for you help! TC

3
  • What have you tried so far? Commented Oct 29, 2018 at 13:52
  • split Commented Oct 29, 2018 at 13:52
  • Welcome to SO. Nothing came up on Google when you searched for 'parse a string in Python'? Commented Oct 29, 2018 at 13:54

2 Answers 2

2

You can do something like:

values = '07|415674|88881234564|3326'
findLength = 4

for val in values.split("|"):
    if(len(val) == findLength):
        print("Found: " + val)

This splits the string on | and loops through the resulting array, checking the length of each value and printing it if it matches the findLength variable.

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

1 Comment

Thank you! Exactly what I needed...
1

Using the string.split() method you can give it a delimiter to split on. In this case

var.split('|')

will split var at every pipe and returns a list of strings

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.