Solved

Whats going wrong here?

Posted on 2006-11-21
12
244 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes how to reset your Windows 10 password when you've forgotten it.
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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