Q:

Example of find() function in Kotlin

0

find() Function

The find() function returns the first match of a regular expression in the given input, beginning at the specified startIndex.

Syntax:

fun find(
    input: CharSequence,
    startIndex: Int = 0
): MatchResult?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Kotlin program to demonstrate the example of find() function

// Example of find() function
fun main()
{
	// Regex to match "oo" in a string
	val pattern = Regex("oo")
	val res : MatchResult? = pattern.find("noncooperations coordination", 2)
	println(res ?.value)
    
	val res1 : MatchResult? = pattern.find("noncooperations coordination", 20)
	println(res1 ?.value)
}

Output:

oo
null

Explanation:

In the first statement "oo" is there from the index 2, but in the second statement "oo" is not there from the index 20.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Example of findAll() function in Kotlin... >>
<< Example of containsMatchIn() function in Kotlin...