Re: String and whitespace problem

From: Sharp (Sharp_at_SharpAddress.com)
Date: 02/21/05


Date: Mon, 21 Feb 2005 08:43:26 GMT


> Hi
>
> I have a sting that contains long stretches of whitespaces between
> characters.
>
> For example:
>
> String str = " A B C
> ";
>
> I would like to include all the characters including the white spaces into
a
> data structure (e.g., ArrayList).
> The code I have written is something like this:
>
> List list = new ArrayList();
> for (int i=0; i<str.length(); i++)
> {
> list.add(str.charAt(i));
> }
>
> Unfortunately it just adds "ABC" into the array list.
> It seems charAt() method ignores whitespaces,
> But the documentation doesn't mention anything about whitespaces.
> Iam happy to add another character in place of the whitespace,
> So I tried using the replaceAll() method from the string class, but that
> didn't work.
>
> Any advice will be appreciated.
>
> Cheers
> Sharp

I forgot to mention that Iam wrapping the characters using the Character
class before adding it into the array.

For example:

    Character ch = new Character(str.charAt(i));
    list.add(ch);

Again any help will be appreciated.

Cheers
Sharp



Relevant Pages

  • RE: Whitespace in passwords
    ... characters (including whitespaces). ... > Audit your website security with Acunetix Web Vulnerability Scanner: ... Up to 75% of cyber attacks are launched on shopping carts, ...
    (Pen-Test)
  • Re: reading text file with MFC
    ... This is a newbie question so I hope somebody can help me. ... with 4 columns delimited by whitespaces. ... What do I do if the product name contains a digit? ... barcode I would have to count the characters to the "beginning" from the ...
    (microsoft.public.vc.mfc)
  • RE: How to identify two byte characters in an MFC program?
    ... and there are two major problems with them. ... SpanExcluding() doesn't return the characters after the first occurence of ... I replaced the double byte whitespaces with single byte whitespaces and then ... characters in an MFC program. ...
    (microsoft.public.vc.mfc)
  • Re: String and whitespace problem
    ... On 21-2-2005 9:43, Sharp wrote: ... >>I have a sting that contains long stretches of whitespaces between ... >>I would like to include all the characters including the white spaces into ... > I forgot to mention that Iam wrapping the characters using the Character ...
    (comp.lang.java.programmer)
  • String matches() method
    ... I would like to use the matchesmethod of the String class to test the ... string's first 3 characters are identical. ... I would like to do this in a general way by using regular expressions. ... Prev by Date: ...
    (comp.lang.java.programmer)