DeathVenom
DeathVenom

Reputation: 394

How to check if a string has a specified character?

I am new to android studio and kotlin. I need to find a way to check if a string contains a char, which is, in this case, "/" I want to form a piece of code in the following manner:

if (string input contains a character "/") = true {
<code>
}
else{
<code>
}

Please tell me how to do this, and if possible, give me the code I'll need to specify as the condition.

Upvotes: 0

Views: 3241

Answers (1)

Andres Rivas
Andres Rivas

Reputation: 162

You can use contains, like this:

val a = "hello/"
val b = a.contains("/")

When the string has the character will return true.

Upvotes: 2

Related Questions