Solved

Whats going wrong here?

Posted on 2006-11-21
12
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

690 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