首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用分隔符识别和打印字符串

如何使用分隔符识别和打印字符串
EN

Stack Overflow用户
提问于 2020-03-29 22:00:46
回答 1查看 27关注 0票数 0

我正在尝试制作一个“测验扫描器”,它使用OCR在线扫描测验,这样我就可以自己从在线来源汇编测验,以便能够离线回答它们。我厌倦了复制和粘贴的事情,只使用OCR代替。

我对光学字符识别部分没有问题,因为我现在遇到的问题是,我需要将问题从选择中分离出来,从正确和错误的选择中分离出来。下面是我尝试分离它们的一个过于简化的代码。

我需要将它们分开,因为我想将其导出到excel中的电子表格中。真的需要你的帮助,一如既往的堆栈溢出社区

代码语言:javascript
复制
import re

scannedmcq = 'Insert Question Here @ A(correct) > B > C > D' #Output of my OCR script
# What if this is the new string
# 'Insert Question Here > A > B > C @ D'
# The Delimiter @ Is the correct answer while > is the wrong answer
# How to Identify and print which part of the string has the delimiter @
text = re.split(r'[@>]\s*', line)
# Manually Printing the strings 
print(text[0])
print(text[1])
print(text[2])
print(text[3])
print(text[4])

sample quiz online

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-29 22:34:31

尝试在字符串中找到@字符的索引,然后在两个索引分开之后就是正确的答案。

代码语言:javascript
复制
scannedmcq = 'Insert Question Here @ A(correct) > B > C > D'

result = scannedmcq[scannedmcq.index('@')+2]
print("Correct Answer is':", result)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60915274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档