• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to split string in JSP?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric,
Please change ; to , (comma) as following line.
<%@ page import="java.util.*,java.io.*;"%>
regds
maha ana
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic