Word Count in PeopleCode Using Regular Expressions

By Chris Malek | Tue, Dec 13, 2011

Here is a quick function that will calculate the word count of a string using Java Regular expressions.

Function wordcountjava(&inString as string) returns integer

   Local JavaObject &patternClass = GetJavaClass("java.util.regex.Pattern");
   Local JavaObject &pattern = &patternClass.compile("(\S+)");
   Local JavaObject &jstring = CreateJavaObject("java.lang.String", &inString);
   Local JavaObject &matches = &pattern.matcher(&jstring.subSequence(0, &jstring.length()));

   Local integer &i;

   While &matches.find()
      &i = &i + 1;
   End-While;
   return &i;
End-Function;
Article Categories
Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Looking for pain-free PeopleSoft web services? 😀
PeopleSoft Simple Web Services (SWS)

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Book
Integration Broker - The Missing Manual

I am in the process of writing a book called "Integration Broker - The Missing Manual" that you can read online.