Re: JSP substring and trim don't work properly




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 &nbsp; 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

.



Relevant Pages

  • Re: Renaming documents from text within the document using existin
    ... StrName = ActiveDocument.Paragraphs.Range.Text ... character was found because you did trim off the first six characters. ... You can use the replace command to remove tab characters from a string and I ...
    (microsoft.public.word.vba.general)
  • Re: Simple Select Query
    ... "Jeanette Cunningham" wrote: ... Marshall Barton provided the solution ... I have a few simple character strings that won't "Trim", ... Why in the world wouldn't the Trim function trim those off? ...
    (microsoft.public.access.gettingstarted)
  • Re: Simple Select Query
    ... Marshall Barton provided the solution ... I have a few simple character strings that won't "Trim", ... Why in the world wouldn't the Trim function trim those off? ... You're correct about the spaces (null strings) which are in fact trailing ...
    (microsoft.public.access.gettingstarted)
  • Re: Trim Function... does not work?
    ... If so, select the character. ... >> Don Guillett ... >>>I am using trim and can not figure out why it does not work!! ... >>> The data is a html I open in Excel, no problem, I save it as Excel and ...
    (microsoft.public.excel.programming)
  • Re: Simple multiplayer?
    ... If characters aren't submitted to the server in real-time, ... their local PC, but after submitting to the server, one finds he no ... other players would be AI controlled monsters with those players stats. ... to the server and your character died while you were away; ...
    (rec.games.roguelike.development)