groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dinko Srko─Ź <dinko.sr...@gmail.com>
Subject Re: search for particular text in a multi-line string
Date Wed, 16 Mar 2016 08:10:35 GMT
It seems to me that `contains()` works as expected.

def str = '''foo bar
baz quux'''

assert str.contains('bar')
assert str.contains('baz')
assert str.contains('r\nb')
assert str.contains('xxx') == false

Cheers,
Dinko


On 16 March 2016 at 08:55, Paul King <paulk@asert.com.au> wrote:
> Can you give an example of what isn't working as expected? contains()
> should be good enough if you have the appropriate line endings in your
> expected text. Otherwise regex searching might be the way to go.
>
> Cheers, Paul.
>
> On Wed, Mar 16, 2016 at 2:28 PM, Deng, Lea <Lea.Deng@ccc.govt.nz> wrote:
>> 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
>>
>> lea.deng@ccc.govt.nz
>>
>>
>>
>> **********************************************************************
>> 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
>> http://www.ccc.govt.nz
>> **********************************************************************

Mime
View raw message