【发布时间】:2020-01-13 07:35:55
【问题描述】:
我设法使用 pytesseract 将发票图像转换为文本。
多行字符串如下所示:
Receipt No: 20191220.001
Date: 20 December 2019
Invoice amount: $400.00
我想提取发票号码,只是使用子字符串的号码(即:20191220.001)。我设法通过index = string.find('Receipt No: ') 获取起始索引,但是当我使用子字符串函数提取数字print(string[index:]) 时,我得到以下结果:
20191220.001
Date: 20 December 2019
Invoice amount: $400.00
但我只想提取第一行。发票编号并非仅定义为 12 个字符,可能或多或少取决于供应商。如何只提取发票编号?我这样做是为了使会计流程自动化。
【问题讨论】:
-
如果您总是知道它的第一行,那么只需阅读第一行,然后在该行上执行 string.find()。
-
这就是你找到开始索引的方式,我猜你需要的是结束索引。然后你可以按
string[index1:index2]切片。多想一点。 -
这能回答你的问题吗? How do I read the first line of a string?
标签: python automation