Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

String Functions

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ! All,
Can any one tell me how to split a string based on particular character like (, or |) and store the values in hash table in JSP.
This is like very urgent. Please help me .
Thanx in advance.
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a snippet of code i did for just this type thing.....I was sending a usernameTo|usernameFrom|date|time string sent to delete multiple emails from a prog.....this will give you an idea of "splitting" them up after that just run them into a hastable with either a loop or anything that flips your cookie. I was building a query (as you can tell)
int numParams= 0;
String name;
String[] values;
Enumeration enum = req.getParameterNames();
if (enum.hasMoreElements())
name = (String)enum.nextElement();
values = req.getParameterValues(name);
for (int x = 0 ; x < values.length ; x++)
String work = values[x];
int index = work.indexOf('|');
String work2 = work.substring(0, index);
String work3 = work.substring(index +1 , work.length());
index = work3.indexOf('|');
String work4 = work3.substring(0, index);

String work5 = work3.substring(index + 1, work3.length());
index = work5.indexOf('|');
String work6 = work5.substring(0, index);
String work7 = work5.substring(index + 1, work5.length());
query = "UPDATE intMail SET deleted=2 WHERE fromUserName='" +work2+ "' AND toUserName='" +work4+ "' AND dateSent='" +work6+ "' AND timeSent='" +work7+ "'";
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may use the library "StringTokenizer". I can't remember the code, you can search in API document.
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the StringTokenizer to achieve this.This class is available in java.util package.
Here is a sample code:
String strTemp = "Test|Test1|Test2";
String strTest = null;
//in this example '|' is the separator
StringTokenizer strToken = new StringTokenizer(strTemp ,"|");
strTest = strToken.nextToken();
//add it in to the hashtable here
hope this helps!!
I knew that guy would be trouble! Thanks tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic