Results 1 to 4 of 4
- 11-09-2009, 05:00 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 6
- Rep Power
- 0
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++){ if(!grammarContains(space[i])){ rString = rString.concat(space[i].trim()+" "); }else{ 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; }
Thanks.
-
I'm no regex pro, but how about,...
cross-posted here: Sun Cross-Post ThreadJava Code:public static void main(String[] args) { String test = " T | W J Y P "; String regex = "[\\s\\|]+"; String[] tokens = test.trim().split(regex); System.out.println(Arrays.toString(tokens)); }
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 05:24 AM.
- 11-09-2009, 05:25 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 6
- Rep Power
- 0
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 05:27 AM.
- 11-09-2009, 07:19 AM #4
Member
- Join Date
- Nov 2009
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Displaying variables in a string?
By shroomiin in forum New To JavaReplies: 4Last Post: 09-21-2009, 03:10 AM -
Maps
By natep67 in forum New To JavaReplies: 8Last Post: 05-06-2009, 03:59 AM -
Trimming URL
By Juuno in forum New To JavaReplies: 1Last Post: 03-10-2009, 05:17 PM -
displaying string
By jamborta in forum AWT / SwingReplies: 6Last Post: 01-23-2008, 07:15 PM -
Google Maps API
By mew in forum New To JavaReplies: 0Last Post: 12-26-2007, 10:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks