• 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: "Jonathan Fleming" <email@hidden>
  • Date: Fri, 11 Jun 2004 17:31:14 +0100

Thanks Michael,

I'm in the process of tesing it, but I think that regex is the way to go, I had forgotten about that.
Somewhat like you, my regex skills are limited so I'm going to have to do a bit of digging possibly if your rust has really set in.


Jonathan :^)


From: Michael Engelhart <email@hidden>
To: "Jonathan Fleming" <email@hidden>
CC: email@hidden
Subject: Re: More Java Than WebObjects
Date: Fri, 11 Jun 2004 09:42:28 -0500

Try messing around with java.util.regex.*
Easier to maintain IMO.

Here's a sample that can be tweaked to better suit your needs (i.e. write a better regex that will do "exactly" what you want). I'm a bit rusty in my regex skills :-)

import java.util.regex.*;

public class Test  {

public static void main(String args[]) {
String matchString = "walls, plumbing, \"painting & decorating\", decorating, \"concrete mixing truck\", concreting, bricklayers";
System.out.println(matchString);
System.out.println("Start length: " + matchString.length());
Pattern p = Pattern.compile("(\\S+)\\s+");
Matcher m = p.matcher(matchString);
StringBuffer sb = new StringBuffer();
while (m.find()) {
sb.append(m.group().trim());
}
System.out.println(sb);
System.out.println("End length: " + sb.length());
}
}


Mike Engelhart
http://www.eztrip.com/

On Jun 11, 2004, at 6:17 AM, 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.



_________________________________________________________________
Use MSN Messenger to send music and pics to your friends http://www.msn.co.uk/messenger
_______________________________________________
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