如何删除字符串之间的连字符和空格?

时间:2017-05-29 12:37:32

标签: android tesseract tess4j

使用Tess4J罐我有一组包含空格和连字符的字符串。

V O D) >3 IIIIIII v .. 18:05Desks ¢ 3HOME FIND DESK FIND COLLEAGUE
  BOOKINGS0, SelfiMGiKIOSK708O4il27197097102,
  LOGSM’KIOSK’O8O47127197107682Monday, May 29 2017 Check-in Successful.
  You have successfully checked in to Desk 5555in 

 - Self-MG-KIOSK—0804-12—19-09—102

 on 0 at 

 - Loc-SM-KlOSK—0804-12-19-10-682

我无法验证字符串,因为它在Loc-SM-KlOSK—0804-12-19-10-682&中获取连字符和白色空格Self-MG-KIOSK—0804-12—19-09—102

4 个答案:

答案 0 :(得分:2)

使用此

yourString.replaceAll("[- ]+", "")

答案 1 :(得分:0)

String sample = "xyz-abc+";
String result = yourString.replaceAll("[-+.^:,]","");

在示例中,如果要删除 - 或+符号,请使用此`replaceAll()。

快乐编码:)`

答案 2 :(得分:0)

删除WHITESPACE和HYPHENS

1。获取你的字符串

String input= "Loc-SM-KlOSK—0804-12-19-10-682";

2。替换所有SPACES和HYPHENS

// REMOVE HYPHENS
String output = input.replaceAll("-","");

// REMOVE WHITESPACES
output = output.replaceAll(" ","");

3。你明白了

结果将存储在输出中,只需将其打印以进行测试

Toast.makeText(getApplicationContext(), output, Toast.LENGTH_LONG).show();

答案 3 :(得分:0)

在上一个答案的第二步,尝试替换此

// REMOVE HYPHENS
String output = input.replaceAll("-","");

// REMOVE WHITESPACES
output = output.replaceAll(" ","");

// REMOVE ANOTHER STUFFS
output = output.replaceAll("—","");

// PRINT RESULTS
Toast.makeText(getApplicationContext(), output, Toast.LENGTH_LONG).show();