wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to split string in JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to split string in JSP?" Watch "How to split string in JSP?" New topic
Author

How to split string in JSP?

Eric Wang
Greenhorn

Joined: Dec 21, 2000
Posts: 22
Hi, All:
I have a simple problem but don't know how should do it? Hope someone help me!
Q1. I have a stringA="A/SG/Fall"
I want to split it to three string, which are A, SG, Fall,
How do split it out?
Q2. I have another stringB="this is my problem!"
I want to get the last three characters for the StringB, I know in ASP can be use Len Function, but don't know in JSP how to do it?
Thank you very much for all the help.
Eric Wang
Satya Narayana
Greenhorn

Joined: Nov 08, 2000
Posts: 9
Q1. I have a stringA="A/SG/Fall"
I want to split it to three string, which are A, SG, Fall,
How do split it out?
A. Use String Tokenizer
StringTokenizer st=new StringTokenizer(stringA,"/");
While(st.hasMoreTokens())
{
String token=st.nextToken() //Here you will get A, sg, fall as separated tokens
}
Q2. I have another stringB="this is my problem!"
I want to get the last three characters for the StringB, I know in ASP can be use Len Function, but don't know in JSP how to do it?
A2. stringB.substring(stringB.length()-3,stringB.length());
Nothing impossible in Java. Just explore it.
:-)
-SaTyA-
Eric Wang
Greenhorn

Joined: Dec 21, 2000
Posts: 22
Hi Satya Narayana:
Thank you very much for the reply. When I testing the program, it come out this problem in my jsp code, but I never have this problem before.
My code is like this:
<%@ page
import="
java.util.*;
java.io.*;
"%>
Error message:
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for JSPE:\tomcat\work\localhost_8080\_0002fSplit_0002ejspSplit_jsp_5.java:15: Class or interface declaration expected.
java.io.*;
^
1 error
Please help!
I really like you said this Nothing impossible in Java.
Regards
Hongwei
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Eric,
Please change ; to , (comma) as following line.
<%@ page import="java.util.*,java.io.*;"%>
regds
maha ana
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to split string in JSP?