Results 1 to 4 of 4
  1. #1
    bh-chobo is offline Member
    Join Date
    Oct 2009
    Rep Power

    Default Need help with String Trimming.. and displaying Keys on maps.

    orking on learning recursion - and i have finally solved the issue.

    The last issue I need to figure out are two minor issues that I can't seem to find out the problems on. After 2 hours of testing and no success... i'm over here.. seeking help and assistance on some pointers.

    I have a method testR that accepts a string = symbol.

    The method will split the String, if it has a '|', or white space.

    But if, for example, the string symbol of this is passed in:

    " T | W J Y P "

    The method below fails to eliminate the trailing and starting white spaces between the letters. Wondering where I should be running it.

    PHP Code:
    	public String testR(String symbol){
    			String s = storeString.get(symbol);
    			String[] parts = s.split("[|]");
    			Random rand = new Random();
    			int pick = rand.nextInt(parts.length);		
    			String x = parts[pick];
    			String[] space = x.split("[ \t]");
    			String rString = "";
    			for( int i=0; i < space.length; i++){
    					rString = rString.concat(space[i].trim()+" ");
    					rString = rString.concat(testR(space[i].trim()));
    			return rString;

    Then I have a method showKeys. Assume that I already have a map and keys/values stored.

    I'm just simply trying to access the keys and display it out.

    But i'm having no luck in that either.

    PHP Code:
    	public String showKeys(){		 
    		String s = "";
    		for (String nonTerminal : storeString.keySet() ) {
          	s.concat(nonTerminal+", ");
    	//	s = "["+s+"]";
    		return s;


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    I'm no regex pro, but how about,...
    Java Code:
       public static void main(String[] args) {
          String test = " T | W J Y P ";
          String regex = "[\\s\\|]+";
          String[] tokens = test.trim().split(regex);
    cross-posted here: Sun Cross-Post Thread

    To the original poster, cross-posting can frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be to not do this, but if you feel that you absolutely must, to at least provide links in both cross-posts to each other.
    Last edited by Fubarable; 11-09-2009 at 06:24 AM.

  3. #3
    bh-chobo is offline Member
    Join Date
    Oct 2009
    Rep Power


    Appreciate your help with the above - i'll try it out and see how it fits in~

    Spent toooo much time banging my head figuring out why its not trimming.

    And lastly - still having issues with display keys from maps... thanks.
    Last edited by bh-chobo; 11-09-2009 at 06:27 AM.

  4. #4
    it career is offline Member
    Join Date
    Nov 2009
    Rep Power

    Default IT CAREEr


    i think your problem is very simple
    just convert that string into integer
    int i=Integer.parseInt(String);

Similar Threads

  1. Displaying variables in a string?
    By shroomiin in forum New To Java
    Replies: 4
    Last Post: 09-21-2009, 03:10 AM
  2. Maps
    By natep67 in forum New To Java
    Replies: 8
    Last Post: 05-06-2009, 03:59 AM
  3. Trimming URL
    By Juuno in forum New To Java
    Replies: 1
    Last Post: 03-10-2009, 06:17 PM
  4. displaying string
    By jamborta in forum AWT / Swing
    Replies: 6
    Last Post: 01-23-2008, 08:15 PM
  5. Google Maps API
    By mew in forum New To Java
    Replies: 0
    Last Post: 12-26-2007, 11:28 AM

Posting Permissions

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