Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Timothy Van Cauwenberge
Timothy Van Cauwenberge
8,958 Points

Help creating a chatbot

I'm working on creating a chatbot in java. I need it to return "Tell em more about father(or mother)" if the user says something like "I hate my mother" or "I hate my father". So I think I would need to find a way to find the string "mother" inside the user's input to trigger the "tell me more about your mother" string from the chatbot. Please help.

Timothy Van Cauwenberge
Timothy Van Cauwenberge
8,958 Points

I figured out I should use the .contains() method on the user's input. But idk how to make it so if the user puts in "Mother"(capital M) instead of "mother" it'll still accept "Mother" like it would "mother"

1 Answer

I'm not very familiar with Java (I'm new, let's put it that way), but I'm sure you can convert the input to lowercase somehow. I would search the Java documentation (look it up).

If there's a function that returns the lowercased version of a string, you can use that. I'm assuming there's a .toLowerCase() function. Notice it might cause an error, since you should find the function that lowercases a string.

If .toLowerCase() were a function on strings, this would probably work:

// Returns true if "testString" variable has the sub string "mother", or else false
testString.toLowerCase().contains("mother");

I hope this helps :grin:

Good luck coding :sparkles: :+1: :sparkles:

:dizzy: ~Alex :dizzy: