Jasbir21
asked on
URGENT!!!-how to split id (|)
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(Qu ery);
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
I have a delete.jsp that receives ids such as user1|user2|user3
String[] id = request.getParameterValues
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(Qu
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use StringTokenizer for this.
Something like this
String ids="user1|user2|user3";
StringTokenizer tokenizer = new StringTokenizer(ids,"|");
String[] ids = new String[tokenizer.countToke ns()];
int i = 0;
for (int i = 0; i< tokenizer.countTokens(); i++)
ids[i] = tokenizer.nextToken();
}
Something like this
String ids="user1|user2|user3";
StringTokenizer tokenizer = new StringTokenizer(ids,"|");
String[] ids = new String[tokenizer.countToke
int i = 0;
for (int i = 0; i< tokenizer.countTokens(); i++)
ids[i] = tokenizer.nextToken();
}
:(( too late again
String names = ids.split("|");
gonna work only with JDK1.4...............
thats why I rely more on tokenizer
thats why I rely more on tokenizer
I realise that, just offering it as an option if Jasbir21 is running 1.4.
just a comment:
String[] names = ids.split("|");
array is returned... :)
Regards!
String[] names = ids.split("|");
array is returned... :)
Regards!
> array is returned... :)
Oops :-)
Oops :-)
ASKER
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
Very very sorry..
Thanks you
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!