0

I have two strings like so:

String a = "on matt to";
String b = "onomatopoeia";

I've been trying to do...

if (a.contains(b)) return true;

It returns true in this case since the character sequence "mat" matches the "onomatopoeia".

I want it to return true only and only if the whole word onomatopoeia is in the String a followed or preceded by however many chars.

Can anyone help me?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ~s.o.s~
0

I wasn't able to figure it out.

I did some research and was under the impression if you put \s*stringContainingOnomatopoeia*\s then that would work so I tried it with a.matches(\s*stringContainingOnomatopoeia*\s) but that returned loads of errors. Even tried to do a.matches("\s*" + stringContainingOnomatopoeia + "*\s") and that still returned quite a few errors.

I have a feeling I just cant get the syntax right

0

> It returns true in this case since the character sequence "mat" matches the "onomatopoeia".

Really? Have you tried running the example you posted? If yes, post a working code which proves your point.

> I want it to return true only and only if the whole word onomatopoeia is in the String a followed or preceded by however many chars.

That's exactly how contains() works. http://ideone.com/LflVb

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.