| | |
breaking a string block into list form
![]() |
•
•
Join Date: Jun 2008
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
the bolded cache is what i change and where i need to add the new code.
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.
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
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.
You do not need to use "split()" in a for loop
Just use this code instead:-
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).
Java Syntax (Toggle Plain Text)
<% String info; String line = cacheManager.getCache(info); for(j = 0; j < parts.length; j++) { String [] parts = line.split(" "); } %>
Just use this code instead:-
Java Syntax (Toggle Plain Text)
<% String info; String line = cacheManager.getCache(info); //for(j = 0; j < parts.length; j++) { String [] parts = line.split(" "); //} %>
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 ?"
"How to ask questions the smart way ?"
![]() |
Other Threads in the Java Forum
- Previous Thread: How to draw a graph in Java applet
- Next Thread: this is what i want it to fo ...
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






