Jess Information

Jess Home
Jess 7 Features
Download Now!
Online Demo

Mailing List
Jess Wiki

More information Related Web Sites
User Contributions
JSR94 Info
Developer's Log
About This Site

JESS ®, the Rule Engine for the JavaTM Platform

Jess Wiki: String Manipulation Tips

To represent carriage return, line feeds, etc. in JESS, the easiest way is to define a defglobal:

(defglobal ?*CR* = (call (new java.lang.Character 13) toString))
(defglobal ?*LF* = (call (new java.lang.Character 10) toString))
(defglobal ?*FF* = (call (new java.lang.Character 12) toString))
(defglobal ?*TAB*  = (call (new java.lang.Character 9) toString))
(defglobal ?*CRLF* = (str-cat ?*CR* ?*LF*))

To trim particular strings off the ends of other strings, define two functions:

(deffunction trim-beginning (?source ?beginning)
   (if (call ?source startsWith ?beginning) then
      (bind ?source (call ?source substring (str-length ?beginning))))
   (return ?source))

(deffunction trim-ending (?source ?ending)
   (if (call ?source endsWith ?ending) then
      (bind ?source (call ?source substring 0 (- (call ?source length) (call ?ending length)))))
   (return ?source))

A better, system independent way of getting the new line character is:

(bind ?*CRLF* (call java.lang.System getProperty "line.separator"))

Front Page | Sandbox | Recent Changes | Powered by Friki | Last Edited: 05 December 2008