-1

Using Tess4J jars I got a set of string containing white spaces and hyphens.

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

I am not able to verify the string as it gets hyphens and whites spaces in Loc-SM-KlOSK—0804-12-19-10-682 & Self-MG-KIOSK—0804-12—19-09—102.

BSMP
  • 4,596
  • 8
  • 33
  • 44
Manish
  • 17
  • 1
  • 9

4 Answers4

2

Use this

yourString.replaceAll("[- ]+", "")
Sandeep dhiman
  • 1,863
  • 2
  • 17
  • 22
  • I am getting this in return doesn't remove all hyphens CheckinSuccessfulYouhavesuccessfullycheckedintoDesk5555inSelfMGKIOSK—0804121909102on0atLocSMKlOSK—O804—12—1910682 – Manish May 30 '17 at 04:23
  • Looks like he needs to remove the emdashes and endashes also. – nguyenq May 30 '17 at 13:20
0
String sample = "xyz-abc+";
String result = yourString.replaceAll("[-+.^:,]","");

In sample, if you want to remove - or + sign then use this `replaceAll().

Happy Coding :)`

coder_baba
  • 447
  • 3
  • 21
0

Removing WHITESPACE and HYPHENS

1. Get your String

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

2. Replace all SPACES and HYPHENS

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

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

3. You got it

The result will be stored in output, Just print it to test it

Toast.makeText(getApplicationContext(), output, Toast.LENGTH_LONG).show();
Sangeeth Nandakumar
  • 1,362
  • 1
  • 12
  • 23
0

On the 2nd step of previous answer, Try substituting this

// 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();
Sangeeth Nandakumar
  • 1,362
  • 1
  • 12
  • 23