我有一个变量拆分段落入行
"Information about this scan : abc version : 5.2.5 pqr version : 201 403061815 hello kdshfldfs;dfkfjljcsdlc sljc lsjclsj csjclks cscjsld"
我想获取“ABC版本”和“焊接工艺评定版本”这一段。
我该如何做到这一点?
我有一个变量拆分段落入行
"Information about this scan : abc version : 5.2.5 pqr version : 201 403061815 hello kdshfldfs;dfkfjljcsdlc sljc lsjclsj csjclks cscjsld"
我想获取“ABC版本”和“焊接工艺评定版本”这一段。
我该如何做到这一点?
如下你可以这样做:
string = "Your Paragraph String"
string = string.split()
abc_version = string[string.index('abc')+3]
和
pqr_version = string[string.index('pqr')+3] #This will give 201
OR
pqr_version = ' '.join(string[string.index('pqr')+3:string.index('pqr')+5]) #This will give 201 403061815
请注明您的pqr
版本字符串的开始和结束。
**谢谢!! ** – user2481458
@ user2481458,没问题。祝你好运! – sshashank124
有一个内置的'str.splitlines'方法。 –
你的问题不清楚。你想要提取什么?文本'“5.2.5”'和'“201 403061815”'?如果是这样,我们应该通过什么规则找到它们(如何定义这些文本的开始,内容和结尾)?请准确,否则你不可能得到有用的答案。 –