• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Can't remove extraneous spacing.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't remove extraneous spacing.


  • Subject: Re: Can't remove extraneous spacing.
  • From: Eric Stewart <email@hidden>
  • Date: Wed, 28 Sep 2005 14:17:57 -0400

Your certainly right, non-breaking spaces are valid unicode, but for
my purposes I need to treat all whitespaces and non-breaking spaces as
the same thing and I need to collapse all them all  between non
whitespace characters.

So I wrote a static method that I put in my String utility class that
converts non-breaking spaces, figure spaces and narrow non-breaking
spaces to spaces. I figure if it's useful now, it will be useful in
the future.

After I run the string through the static conversion method, I then
use the replaceAll("\\s{2,}", " ") to collapse and convert all
whitespaces to a single space between non-whitespace characters.

Thanks for everyone's help, character manipulations are a weakness of
mine, but I'm starting to get it.

Eric Stewart

On 9/28/05, Arturo Perez <email@hidden> wrote:
> Non-breaking space is a valid unicode character (shame it's not
> considered whitespace, though).
>
> So why can't you do something like
> value = value.replaceAll( "(\u00A0|\\s)+", " " ).trim();
>
> Here's a handy page for getting unicode values
> http://www.fileformat.info/info/unicode/char/search.htm
>
> -arturo
>
> Eric Stewart wrote:
> > I tried the code you suggested:
> > value = value.replaceAll( "(\\Q\\E|\\s)+", " " ).trim();
> >
> > It did not result in the expected result, here is the result.
> > " abc    bb " --> "a b c  b b"
> >
> >
> >
> > On 9/28/05, LD <email@hidden> wrote:
> >
> >>Hi there,
> >>
> >>On 28/09/2005, at 2:23 PM, Eric Stewart wrote:
> >>
> >>
> >>>I figured out the problem but it's turned up something I don't
> >>>understand.
> >>>
> >>>I'm getting the input from the request like this:
> >>>
> >>>String value = context().request().stringFormValueForKey
> >>>("input_field");
> >>>
> >>>When someone enters the html entity for a non-breaking space it
> >>>is not collapsed with the replaceall() I was using, which makes
> >>>[sense].
> >>>
> >>>[...]
> >>>Also, how do I convert all the incoming non-breaking spaces to normal
> >>>spaces which will collapse with the replaceall() method?
> >>
> >>String value = context().request().stringFormValueForKey
> >>( "input_field" );
> >>value = value.replaceAll( "(\\Q\\E|\\s)+", " " ).trim();
> >>
> >>e.g.,
> >>" abc    bb " --> "abc bb"
> >>
> >>with regards,
> >>--
> >>
> >>LD
>
>
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Can't remove extraneous spacing. (From: Eric Stewart <email@hidden>)
 >Re: Can't remove extraneous spacing. (From: Art Isbell <email@hidden>)
 >Re: Can't remove extraneous spacing. (From: Eric Stewart <email@hidden>)
 >Re: Can't remove extraneous spacing. (From: LD <email@hidden>)
 >Re: Can't remove extraneous spacing. (From: Eric Stewart <email@hidden>)
 >Re: Can't remove extraneous spacing. (From: Arturo Perez <email@hidden>)

  • Prev by Date: Re: Can't remove extraneous spacing.
  • Next by Date: Re: WOCookie value() returns quoted/parenthesized string not string
  • Previous by thread: Re: Can't remove extraneous spacing.
  • Next by thread: Re: Can't remove extraneous spacing.
  • Index(es):
    • Date
    • Thread