groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <>
Subject RE: search for particular text in a multi-line string
Date Wed, 16 Mar 2016 12:38:27 GMT
Contains works, but depending on your situation you might need to normalize data. If you don't
know where your line breaks are, for example if you want to find "the cow jumped over the
moon" but the string is "I read a book. It is called the Cow\nJumped Over the Moon", in this
case you need to normalize the input. You can normalize any sequence of whitespace (including
newlines) to a single space and do a case insensitive comparison (or convert everything to
lower case).


From: Deng, Lea []
Sent: Wednesday, March 16, 2016 12:29 AM
To: '' <>
Subject: search for particular text in a multi-line string

I'd like to have your suggestions on searching for particular text in a multi-line string.

I found the contains() method does not work:
boolean isContain = multi_line_String.contains(expectedText)

Do I have to break down my multi line string into single lines for the search? I think that
may slow down the search.

Or is there an object I could use to declare the multi line, instead of using String?

many thanks,
Kind Regards
Lea Deng

Creating connections to make IT easier for everyone

Lead Test Analyst
IT Regulatory Services Team
Christchurch City Council
New Zealand
DDI: +64 (3) 941 88 55
Extn: 8855<>

This electronic email and any files transmitted with it are intended
solely for the use of the individual or entity to whom they are addressed.

The views expressed in this message are those of the individual sender
and may not necessarily reflect the views of the Christchurch City Council.

If you are not the correct recipient of this email please advise the
sender and delete.

Christchurch City Council

This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.

View raw message