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

kutschkem
  • 6,987
  • 3
  • 17
  • 48
todd328
  • 41
  • 2
  • 5

2 Answers2

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

samlli
  • 106
  • 5
1

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.

Mark
  • 4,808
  • 2
  • 20
  • 29