Re: JSP substring and trim don't work properly
- From: nino9stars@xxxxxxxxx
- Date: 16 Aug 2006 17:01:17 -0700
nino9stars@xxxxxxxxx wrote:
But Soren's suggested line was
sb.append("[code:" + c + "]");
note the position of "[" before "code"
and this is what it returned...
[code: ][code: ]John Smith[code: ]
That suggests that your code uses Soren's suggestion and that instead of
cutting and pasting you are retyping. This would mean that newsgroup
readers are being deceived into thinking they are seeing your real code
when they are not. It's best to cut and paste.
If you were using Soren's code then your "space" character is not an
ASCII space but a single character that looks like the two character
sequence ": " (colon, space) when displayed to you. Could it be that you
have mismatched encodings (e.g. UTF-8 vs Latin-1 etc)
Or maybe you have the colon in the real code and not in the code you posted?
As I said, I think it's best to cut and paste code into news group
postings, not re-type them.
You're right. I'm sorry. I actually had removed that original else
statement, added the c==' ' value (for a space) to the original code
and it ended up working how I intended trim() to work. I was trying to
just retype to get the message out quickly. Sorry about that...
So it doesn't say what the character was, but it still looks like a
space on screen?
Try this, then an ascii space would show as [code:32]
sb.append("[code:" + (int)c + "]");
--------------------------8<------------------------
public class NonAscii {
public static void main(String[] args) {
String s = "foo bar";
char[] chars = s.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (c >= 'a' && c <= 'z' || c >= '>' && c <= 'Z')
sb.append(c);
else
sb.append("[code:" + (int)c + "]");
}
System.out.println("sb='"+sb+"'");
}
}
------------------------8<----------------------------
sb='foo[code:32]bar'
I tried this and the code for the blanks in front of the name and email
was (hold on... I'm copying and pasting)...
[code:160]Jon[code:32]Smith[code:160]
So, I guess the next question is what is code:160 ??? I guess trim()
wouldn't know how to handle that? Could it have something to do with
being submitted by a post over the web?
I think I figured out the root of the problem... When I was submitting
information in the code, apparently I had used to keep my
spacing appropriate. I assumed this would be considered a space when
sent over the line. My guess is that a null blank space is different
from a regular space in how trim() handles that information. I haven't
had time to test to see if trim() works now that I took out those null
blank spaces, but when I do, I will be sure to post again.
Thanks again so much for helping. I don't think I would have figured
out the solution if I wasn't pointed in the right direction!
Nino
.
- Follow-Ups:
- Re: JSP substring and trim don't work properly
- From: Ian Wilson
- Re: JSP substring and trim don't work properly
- References:
- JSP substring and trim don't work properly
- From: nino9stars
- Re: JSP substring and trim don't work properly
- From: Soren Kuula
- Re: JSP substring and trim don't work properly
- From: nino9stars
- Re: JSP substring and trim don't work properly
- From: Mark Space
- Re: JSP substring and trim don't work properly
- From: nino9stars
- Re: JSP substring and trim don't work properly
- From: Ian Wilson
- Re: JSP substring and trim don't work properly
- From: nino9stars
- JSP substring and trim don't work properly
- Prev by Date: can this code be improved
- Next by Date: Re: can this code be improved
- Previous by thread: Re: JSP substring and trim don't work properly
- Next by thread: Re: JSP substring and trim don't work properly
- Index(es):
Relevant Pages
|