N
nino9stars
Hello,
I am trying to do (what I think) is a simple task. I am trying to take
in a list of information, parse through it, and display it. However,
for some reason, the trim() String function isn't working right. I am
using JSDK 1.4 on Tomcat 4.0 (if that matters)...
A sample of the information that is sent:
Jon Stewart <[email protected]>, Jane Doe <[email protected]>, (e-mail address removed),
With that, I want to parse the information into an array with no
leading or trailing spaces... Here is my code:
//We have to look through the actual inputted information
String[] s_final = new String[2];
String[] NONList = request.getParameter("gnon").split(",");
for (int x=0; x < NONList.length; x++) {
String name = "";
String nameTrim = "";
String email = "";
if (s_string.indexOf("<") != -1) {
//There is a name and an email
//It used to be like this... but it didn't work either...
//name = NONList[x].substring(0, NONList[x].indexOf("<")).trim();
name = NONList[x].substring(0, NONList[x].indexOf("<"));
nameTrim = name.trim();
email = NONList[x].substring(NONList[x].indexOf("<")+1,
NONList[x].indexOf(">"));
s_final[0] = nameTrim;
s_final[1] = email;
} else {
//There is only an email
email = NONList[x].trim();
s_final[0] = "";
s_final[1] = email;
}
out.println("Name: -"+tmp[0]+"-<BR>");
out.println("Email: -"+tmp[1]+"-<BR>");
}
I am expecting to get an output like this:
Name: -Jon Stewart-
Email: (e-mail address removed)-
Name: -Jane Doe-
Email: (e-mail address removed)-
Name: --
Email: (e-mail address removed)-
Instead I am getting the following output:
Name: -Jon Stewart -
Email: (e-mail address removed)-
Name: - Jane Doe -
Email: (e-mail address removed)-
Name: --
Email: - (e-mail address removed)-
In case it's hard to tell, I am trying to point out that there are
spaces in front and after most of the names and emails. I thought that
is what trim() was supposed to get rid of????
I am seriously baffled. Any suggestions, or comments are greatly
appreciated. Maybe if there is even a better way to get to my result.
Let me know if anything is confusing.
Thanks in advance,
Nino Skilj
I am trying to do (what I think) is a simple task. I am trying to take
in a list of information, parse through it, and display it. However,
for some reason, the trim() String function isn't working right. I am
using JSDK 1.4 on Tomcat 4.0 (if that matters)...
A sample of the information that is sent:
Jon Stewart <[email protected]>, Jane Doe <[email protected]>, (e-mail address removed),
With that, I want to parse the information into an array with no
leading or trailing spaces... Here is my code:
//We have to look through the actual inputted information
String[] s_final = new String[2];
String[] NONList = request.getParameter("gnon").split(",");
for (int x=0; x < NONList.length; x++) {
String name = "";
String nameTrim = "";
String email = "";
if (s_string.indexOf("<") != -1) {
//There is a name and an email
//It used to be like this... but it didn't work either...
//name = NONList[x].substring(0, NONList[x].indexOf("<")).trim();
name = NONList[x].substring(0, NONList[x].indexOf("<"));
nameTrim = name.trim();
email = NONList[x].substring(NONList[x].indexOf("<")+1,
NONList[x].indexOf(">"));
s_final[0] = nameTrim;
s_final[1] = email;
} else {
//There is only an email
email = NONList[x].trim();
s_final[0] = "";
s_final[1] = email;
}
out.println("Name: -"+tmp[0]+"-<BR>");
out.println("Email: -"+tmp[1]+"-<BR>");
}
I am expecting to get an output like this:
Name: -Jon Stewart-
Email: (e-mail address removed)-
Name: -Jane Doe-
Email: (e-mail address removed)-
Name: --
Email: (e-mail address removed)-
Instead I am getting the following output:
Name: -Jon Stewart -
Email: (e-mail address removed)-
Name: - Jane Doe -
Email: (e-mail address removed)-
Name: --
Email: - (e-mail address removed)-
In case it's hard to tell, I am trying to point out that there are
spaces in front and after most of the names and emails. I thought that
is what trim() was supposed to get rid of????
I am seriously baffled. Any suggestions, or comments are greatly
appreciated. Maybe if there is even a better way to get to my result.
Let me know if anything is confusing.
Thanks in advance,
Nino Skilj