ADVERTISEMENT
ADVERTISEMENT

Example of find() function in Kotlin

Learn about the find() function in Kotlin, and demonstrate the example of the find() function.
Submitted by IncludeHelp, on March 25, 2022

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?

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.

Kotlin Regular Expression (Regex) Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.