Solved

Whats going wrong here?

Posted on 2006-11-21
12
237 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
Comment Utility
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
Comment Utility
do u get any errors??
0
 

Author Comment

by:fox_statton
Comment Utility
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
Comment Utility
decalre it as an array
String[] temp
then itwill be okay
0
 
LVL 29

Expert Comment

by:bloodredsun
Comment Utility
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
Comment Utility
If my JDK isnt 1.4+ is there another way to split?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 5

Expert Comment

by:deeppra
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
Hi,
its still not working :(
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

12 Experts available now in Live!

Get 1:1 Help Now