?
Solved

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

Posted on 2003-11-25
10
Medium Priority
?
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 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