Solved

Whats going wrong here?

Posted on 2006-11-21
12
240 Views
Last Modified: 2012-05-05
string updated;
updated = "blah,blah";
String temp;
String temp_second;
temp = updated.split(',');


Im not really familar with JSP, do I need to import a special library or something to get this to work?
0
Comment
Question by:fox_statton
  • 5
  • 5
  • 2
12 Comments
 
LVL 5

Expert Comment

by:deeppra
ID: 17986065
put like this
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
<%
String updated;
updated = "blah,blah";
String temp;
String temp_second;
temp = updated.split(',');
%>
</body>
</html>


What u want to print?? ist temp??
0
 
LVL 5

Expert Comment

by:deeppra
ID: 17986070
do u get any errors??
0
 

Author Comment

by:fox_statton
ID: 17986106
Hi, its part of a larger script, but it seems that the

temp[] = updated.split(',');

is giving an error:

Unable to compile class for JSP An error occurred between lines: 16 and 38 in the jsp


cannot resolve symbol symbol : method split (char) location: class java.lang.String String temp[] = updated.split(','); ^ 1
0
 
LVL 5

Expert Comment

by:deeppra
ID: 17986118
decalre it as an array
String[] temp
then itwill be okay
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 17986430
Another issue might be JDK support. If you are compiling/running on a JDK version 1.3 or older, it will not support the String.split() method which was only introduce in JDK 1.4. You are also trying to use a char ('single quotes') rather than the String("double quotes") in the regex of the String.split method.

string updated = "blah,blah";
String[] temp = updated.split(",");

Should work fine assuming that your JDK is 1.4+.
0
 

Author Comment

by:fox_statton
ID: 17986504
If my JDK isnt 1.4+ is there another way to split?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:deeppra
ID: 17986590
you can use StringTokenizer class for splitting the string
refer this doc
http://java.sun.com/j2se/1.3/docs/api/java/util/StringTokenizer.html
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 17986592
You have to use the more cumbersome StringTokenizer

    String aString = "word1,word2,word3";
    StringTokenizer parser = new StringTokenizer(aString, ",");
    while (parser.hasMoreTokens()) {
        //do stuff here
        processWord(parser.nextToken()); //this nextToken() method returns a String
    }
0
 

Author Comment

by:fox_statton
ID: 17986704
Hi,
I ve managed to get it working... kinda...


String updated = "November 20,2006";
String[] temp = updated.split(",");
String[] temp_second = temp[0].split(" ");
updated = temp_second[1]+" "+temp_second[2]+" "+temp[1];

out.println(updated);

the problem is that updated is coming out as "November 2006" instead of "20 November 2006"

Any ideas?
0
 

Author Comment

by:fox_statton
ID: 17986923
Ok, so I figure its something to do with the fact that those two arrays have integers, so I tried a different approach, but its still not working:

String[] temp = updated.split(" ");
Int[] tempint = updated.split(" ");
out.println(tempint[1]);
out.println(temp[0]);
out.println(tempint[2]);
0
 
LVL 5

Accepted Solution

by:
deeppra earned 488 total points
ID: 17987152
>>String updated = "November 20,2006";
>>String[] temp = updated.split(",");
>>String[] temp_second = temp[0].split(" ");
>>updated = temp_second[1]+" "+temp_second[2]+" "+temp[1];

should be like this
String updated = "November 20,2006";
String[] temp = updated.split(",");
String[] temp_second = temp[0].split(" ");
updated = temp_second[1]+" "+temp_second[0]+" "+temp[1];
0
 

Author Comment

by:fox_statton
ID: 18002769
Hi,
its still not working :(
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what is stuck threads? 3 97
tomcat users xml 7 105
servlet init param and contect param 3 59
'exit' is not valid keyword in java 14 147
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now