Results 1 to 2 of 2
  1. #1
    A.M.S is offline Member
    Join Date
    Dec 2008
    Posts
    17
    Rep Power
    0

    Default String Splitting

    Hi,


    I have a text file and I read it by buffered reader ..
    but when I split each line by split() method I face a problem
    that it doesn't split the line as I want, here's an example :

    *let the last line of the text above is read and stored in a string named "A".

    String [] words = A.split("[,. ]");

    then I wanted to determine location of each word in this string.. (e.g the word "that" is stored in cell [0] in the array)

    but when I was working and trying it, it gave me the word "here's" in the cell [10] and I want it in cell [9]..

    this's the problem, I looked everywhere but couldn't find solution :( !!


    Thanks :)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    String s =
        "that it doesn't split the line as I want, here's an example :";
    String[] x = s.split("\\s");
    System.out.println("x: " + java.util.Arrays.toString(x));

Similar Threads

  1. Reading files and splitting them
    By Dieter in forum Advanced Java
    Replies: 5
    Last Post: 09-30-2009, 09:46 AM
  2. Array splitting
    By Lunarion in forum New To Java
    Replies: 3
    Last Post: 04-17-2009, 08:00 AM
  3. Splitting paragraph into line statements
    By mintu in forum New To Java
    Replies: 3
    Last Post: 02-28-2009, 08:41 AM
  4. Splitting single string into array elements
    By phil128 in forum New To Java
    Replies: 11
    Last Post: 01-12-2009, 11:51 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •