breaking a string block into list form

Reply

Join Date: Jun 2008
Posts: 4
Reputation: vtsmokey88 is an unknown quantity at this point 
Solved Threads: 0
vtsmokey88 vtsmokey88 is offline Offline
Newbie Poster

breaking a string block into list form

 
0
  #1
Jun 5th, 2008
My problem is I have a cache file that I'm pulling in from a seperate source. The cache contains a long string that would look something like this except much longer.

myexample=1 status=0 timesHit=2500

Basically I need help figuring out how to break this up into
myexample=1
status=0
timesHit=2500

The java code is written inside of html code but I know the html code well enough.
I don't think this is overly complicated but I just can't seem to get it to work.


<%
		final CacheManager cacheManager = CacheManager.getInstance();
  		String[] names = cacheManager.getCacheNames();
  		Arrays.sort(names);
  %>			
<%	
		for (int i = 0; i < names.length; i++) { 
			Cache cache = cacheManager.getCache(names[i]);
  %>
  			<table border="1" bordercolor="#cc0000">
  			<tr class="tan">
  			<td colspan="3">
			
      			<div class="largeHeader2"> Cache <%= i %>: <%=names[i]%> </div>
      			<div class="smallCopy"> <table>
		<%	
			String info;
			String line = cacheManager.getCache(info);
			for(j = 0; j < parts.length; j++) {
			String [] parts = line.split(" ");
			}
		%>

the bolded part is the part i've edited. Everything else should be correct. The bold part is the part I'm having trouble with.
The bold is very wrong but I have been trying to figure this out for many hours so this is desperation code.

The original code looked like this so that you can see the parts i have screwed up.

<%
		final CacheManager cacheManager = CacheManager.getInstance();
  		String[] names = cacheManager.getCacheNames();
  		Arrays.sort(names);
  %>			
  <%	
		for (int i = 0; i < names.length; i++) { 
			Cache cache = cacheManager.getCache(names[i]);
  %>
  			<table border="1" bordercolor="#cc0000">
              <tr class="tan">
              <td colspan="3">
            
                  <div class="largeHeader2"> Cache <%= i %>: <%=names[i]%> </div>
                  <div class="smallCopy"> <%= cache %> Total elements cached currently: <%= cache.getKeysWithExpiryCheck().size() %> </div>
            </td>
  			</tr>

the bolded cache is what i change and where i need to add the new code.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: breaking a string block into list form

 
0
  #2
Jun 5th, 2008
I hope this doesn't sound too newby but have you tried looking into String Tokenizer? i'm assuming the information is in Strings so you can learn the StringTokenizer class to seperate your string based on a " " or space token.

Oh wait it looks like you're using Javascript... I don't know of any JavaScript classes/functions to help you X_X
Last edited by Alex Edwards; Jun 5th, 2008 at 10:23 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,176
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: breaking a string block into list form

 
0
  #3
Jun 6th, 2008
You do not need to use "split()" in a for loop
  1. <%
  2. String info;
  3. String line = cacheManager.getCache(info);
  4. for(j = 0; j < parts.length; j++) {
  5. String [] parts = line.split(" ");
  6. }
  7. %>

Just use this code instead:-
  1. <%
  2. String info;
  3. String line = cacheManager.getCache(info);
  4. //for(j = 0; j < parts.length; j++) {
  5. String [] parts = line.split(" ");
  6. //}
  7. %>
Note:-
I have commented out the for loop here
And by the have you noticed how you are using the "parts" object(in the for loop) before actually declaring it (which is inside the loop).
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC