-4

Hi,

I'm trying to retreive the data from excel sheet using java. Please tell me how can I divide following lines into array like 0th element is 0171185 1st element is 11200113 2nd element is 404630G 40X46 1.2-MIL GRAY

One of the line is

0171185(MORE THAN A TAB SPACE)11200113 (MORE THAN A TAB SPACE)404630G 40X46 1.2-MIL GRAY

  • 2
    Have you tries anything, if yes please provide the code. – ajay.patel Jul 08 '13 at 12:48
  • What have you tried? You can try String split http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String%29 – Makky Jul 08 '13 at 12:49
  • Yes I have used ItemDescdup=fouritems.get(id).split("\\s+"); but it is dividing irrespective of spaces , like when it finds a space it divides and stores with an index. – user2517224 Jul 08 '13 at 12:50

2 Answers2

2

Assuming your line is stored in a String called myString:

myString.split("[\\W]{2,}"))

will use "more than one space or tabulator" as your delimitor. So single spaces and/or tabulators will not split your tokens.

Edit: as noted by Litari, \\s is also possible instead of \\W depending on which characters you want to split exactly.

Michael Lang
  • 3,902
  • 1
  • 23
  • 37
0

Answered here previously: How do I split a string with any whitespace chars as delimiters?

The short answer is, use \\s as delimiter since it's equivalent to [ \\t\\n\\x0B\\f\\r]

Community
  • 1
  • 1
Johan Hjalmarsson
  • 3,433
  • 4
  • 39
  • 64