Solved

URGENT!!!-how to split id (|)

Posted on 2003-11-25
10
292 Views
Last Modified: 2012-05-04
hi,

 I have a delete.jsp that receives ids such as user1|user2|user3

String[] id = request.getParameterValues("id") ;

    for(int i=0; i < id.length; i++)

    {

out.println(id[i]);

      String Query = "delete FROM volunteer where username='"+id[i]+"'";
      int status= statement.executeUpdate(Query);



 

  if(status != 0)
  {
   out.println("Entry successfully deleted.");
  }
 
  else
  {
  out.println("Deletion not successful");
  }

}

}


My problem is id[0] is user1|user2|user3


i need to split it into

id[0]=user1
id[1]=user2
id[2]=user3 and etc

i mean discard | and put into array.


Pls help , i need it urgently
0
Comment
Question by:Jasbir21
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 4

Expert Comment

by:vk33
ID: 9817693
Hi!

It's quite simple when using StringTokenizer:

import java.util.*;
...
String id = request.getParameter("id");
StringTokenizer parser = new StringTokenizer(id,"|");
while (parser.hasMoreTokens()) {
   String query = "DELETE FROM volunteer WHERE username = '" + parser.nextToken() + "'";
   ...
}

Good luck!
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 100 total points
ID: 9817700
well first I am not sure why you are getting id[0] as user1|user2 format but.. this is what you can do..

StringTokenizer st = new StringTokenizer(id[0],"|");
String[] ar = new String[st.countTokens()];
int i=0;
while(st.hasMoreTokens())
{
ar[i]=st.nextToken();
i++
}
This will put all the stuff in String array ar.
Hope this helps
Regards
0
 
LVL 2

Expert Comment

by:DidierD
ID: 9817807
You can use StringTokenizer for this.

Something like this

String ids="user1|user2|user3";
StringTokenizer tokenizer = new StringTokenizer(ids,"|");

String[] ids = new String[tokenizer.countTokens()];
int i = 0;
for (int i = 0; i< tokenizer.countTokens(); i++)
  ids[i] = tokenizer.nextToken();
}
0
 
LVL 2

Expert Comment

by:DidierD
ID: 9817816
:(( too late again
0
 
LVL 92

Expert Comment

by:objects
ID: 9822759
String names = ids.split("|");
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9822947
gonna work only with JDK1.4...............
thats why I rely more on tokenizer
0
 
LVL 92

Expert Comment

by:objects
ID: 9822950
I realise that, just offering it as an option if Jasbir21 is running 1.4.
0
 
LVL 4

Expert Comment

by:vk33
ID: 9823018
just a comment:

String[] names = ids.split("|");

array is returned... :)

Regards!
0
 
LVL 92

Expert Comment

by:objects
ID: 9823027
> array is returned... :)

Oops :-)
0
 

Author Comment

by:Jasbir21
ID: 9831041
I am very sorry for the late response, i got stuck in another question, that i couldn't start with this until that problem was not solved.the program did not work , now it does.

  Very very sorry..

Thanks you
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now