gpt4 book ai didi

java - 捕获数据并将其传递到文本字段中

转载 作者:行者123 更新时间:2023-11-30 07:42:32 24 4
gpt4 key购买 nike

我目前正在开发一个光学字符识别(OCR)应用程序,它将把识别的数据从名片传递到联系人中。我已经设法recognized the data来自名片。

问题是如何识别该文本框中的诸如电话号码之类的内容并将其传递到 phone contact textfield

最佳答案

你可以试试这个:

String text  = "This is the text 2432423 which contains phone numbers 56565555";

Pattern pattern = Pattern.compile("\\d{5,12}"); // at least 5 at most 12
// before match remove all the spaces, to ensure the length on numbers is OK it will work more better.
Matcher matcher = pattern.matcher(text.replaceAll(" ", ""));
while (matcher.find()) {
String num = matcher.group();
System.out.println("phone = " + num);
}

这是输出:

phone = 2432423
phone = 56565555

注意:至少和最多,您可以根据您的要求进行更改。

关于java - 捕获数据并将其传递到文本字段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34459415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com