• 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: More Java Than WebObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More Java Than WebObjects


  • Subject: Re: More Java Than WebObjects
  • From: Daniel Mejia <email@hidden>
  • Date: Sat, 12 Jun 2004 01:08:10 -0500

Why do you want to count the spaces, could no be easier to count only
the commas?

Daniel.




On Jun 12, 2004, at 12:01 AM, email@hidden
wrote:

>
> From: Sam Barnum <email@hidden>
> Date: June 11, 2004 2:37:49 PM CDT
> To: WebObjects WebObjects <email@hidden>
> Subject: Re: More Java Than WebObjects
>
>
> You might also take a look at java.io.StreamTokenizer, which has quote
> support built-in.  Maybe overkill, but nice to use something that's
> already there.
>
> On Jun 11, 2004, at 9:39 AM, Jonathan Fleming wrote:
>
>>> From: Adam Ramadan <email@hidden>
>>> To: Jonathan Fleming <email@hidden>
>>> Subject: Re: More Java Than WebObjects
>>> Date: Fri, 11 Jun 2004 10:54:35 -0400
>>>
>>> A simple approach would be to add a boolean variable, inQuote, and
>>> use that to track whether or not you're within a quoted phrase. So
>>> asy ou are iterating through the characters and reach a quote you
>>> set inQuote <- !inQuote, and when you reach a whitespace character
>>> you can use the value of inQuote to decide whether to count the
>>> word.
>>
>> What happens if the user has accidently only supplied one open quote
>> and not a closed quote? If I use your approach, which sounded good at
>> first, I'd end up not reading enough spaces therefore having too many
>> words... afterthought: but then I could set the boolean to look for a
>> second quotation mark, else count the spaces... yeah maybe your
>> approach is good afterall, i'll try it.
>>
>> regards
>> Jonathan
>>
>>> For anything more complicated you might want to look at regular
>>> expressions.
>>>
>>> Adam
>>>
>>> Jonathan Fleming wrote:
>>>
>>>> What's the best way to write code that will count the spaces
>>>> between each word but not prases that are sourounded by double
>>>> quotation marks eg. there are 2 phrases in the example below making
>>>> up a total of 6 words (6 spaces), but how can avoid counting the
>>>> spaces in the phrases?:
>>>> walls, plumbing, "painting & decorating", decorating, "concrete
>>>> mixing truck", concreting, bricklayers
>>>>
>>>> This is the code I have so far:
>>>>
>>>>    public static String wordCounter(String s, int numOfWords){
>>>>        int wordCounter=0;
>>>>        int numToReduce=0;
>>>>        for (int index=0;index<s.length();index++) {
>>>>            char c = s.charAt(index);
>>>>            if (Character.isWhitespace(c)) {wordCounter++;}  //
>>>> Counts the spaces.
>>>>        }
>>>>        if (wordCounter > numOfWords) {
>>>>            numToReduce=wordCounter - numOfWords;
>>>>            throw new NSValidation.ValidationException
>>>>            ("You are only allowed to enter "+numOfWords+" words,
>>>> but you have entered "+wordCounter+". <br />"+
>>>>             "You'll need to delete any "+numToReduce+" of these
>>>> words.");
>>>>        }
>>>>        return s;
>>>>    }
>>>>
>>>> _________________________________________________________________
>>>> Want to block unwanted pop-ups? Download the free MSN Toolbar now!
>>>> http://toolbar.msn.co.uk/
>>>> _______________________________________________
>>>> webobjects-dev mailing list | email@hidden
>>>> Help/Unsubscribe/Archives:
>>>> http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>>>> Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: More Java Than WebObjects
  • Next by Date: Re: More Java Than WebObjects
  • Previous by thread: Re: More Java Than WebObjects
  • Next by thread: Re: More Java Than WebObjects
  • Index(es):
    • Date
    • Thread