Replace Stringparts

248
3
05-08-2020 03:55 AM
JohannesBierer
Regular Contributor

Hello,

I have an array looking like this 082640-000-07332/001 and would like to convert it to 0826400000733200100 for a search clause?

I tried this:

sc = line.replace("[", "") # 082640-000-07332/001 convert to 0826400000733200100
sc2 = sc.replace("]", "")

sc21 = sc2.replace("-", "")
sc22 = sc21.replace("/", "")
sc23 = "{}{}".format(sc21, "00")

sc3 = "{} = '{}'".format(field, sc23)
print sc3

but this code results in this (print sc3):

FLURSTUECKSKENNZEICHEN = 'u'08264000007138/000'00'

Any help would be great?

0 Kudos
3 Replies
JohannesBierer
Regular Contributor

This worked for me:

  sc = line.replace("[", "") # 082640-000-07332/001 convert to 0826400000733200100
  sc2 = sc.replace("]", "")

  sc21 = sc2.replace("-", "")
  sc22 = sc21.replace("/", "")
  sc23 = "{}{}".format(sc22, str("00"))
            
  sc24 = sc23.replace("'", "")
  sc25 = sc24.encode('ascii')
  sc26 = sc25.replace("u", "")
            
  sc3 = "{} = '{}'".format(field, sc26)
  print sc3
0 Kudos
JohannesBierer
Regular Contributor

Thank you David, didn't see your answer. But it works with one "/", I only made a big mistake in line 6 :)

0 Kudos
DavidPike
MVP Frequent Contributor

Yes Johannes, deleted as I was confusing it with a backslash...

0 Kudos