Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Java split problem..

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    My Mood
    Mellow
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Java split problem..

    Hello.. I'm new to this forum. Please help me.
    I've a string.
    search = "Empty Jars$@$301". I need to split the string on "$@$"

    String arr[] = search.split("[$@$]");

    the array is something like this

    arr = (Empty Jars, , ,301)

    I dont know y i am getting 2 blank spaces. there are no white spaces or new line chars in the string..
    Last edited by arch; April 11th, 2011 at 06:52 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java split problem..

    The split function takes a regular expression. The dollar sign means "end of line". You'll have to escape it using two backslashes in order to mean literally "dollar sign".

    Recommended reading: Pattern (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    arch (April 11th, 2011)

  4. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    My Mood
    Mellow
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java split problem..

    String arr[] = searchFor.split("[\\$@\\$]");

    i did something like this.. It doesn't work.. i get the same result. Thanks for replying..

  5. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    My Mood
    Mellow
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java split problem..

    Thanks it worked.. Made a small syntax error..

  6. #5
    Junior Member
    Join Date
    Apr 2011
    Posts
    4
    My Mood
    Mellow
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java split problem..

    How can i start a new thread I cant see a link anywhere as to start a new thread please help me..

  7. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java split problem..

    Just go to the appropriate forum and it should be at the top.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help me split and then join a file
    By babbupandey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 13th, 2010, 12:20 PM
  2. Thread Hangs at split method.
    By kailasvilaskore in forum Threads
    Replies: 1
    Last Post: November 26th, 2010, 12:13 PM
  3. MVC - Split the Java servlet(help needed)
    By kamweshi in forum Java Servlet
    Replies: 1
    Last Post: October 18th, 2010, 09:02 AM
  4. Java Chat Problem
    By skillwill2002 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 4th, 2010, 10:30 AM
  5. java problem
    By Mj Shine in forum Java Theory & Questions
    Replies: 1
    Last Post: August 14th, 2009, 12:24 AM