- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 81字
- 2021-07-23 19:05:53
How to do it...
- Declare a new interface called EmailValidator:
interface EmailValidator {}
- Add a string property responsible for holding the current text input:
interface EmailValidator {
var input: String
}
- Add the isEmailValid() function to the interface:
interface EmailValidator {
var input: String
fun isEmailValid(): Boolean = input.contains("@")
}
- Add the getUserLogin() function:
interface EmailValidator {
var input: String
fun isEmailValid(): Boolean = input.contains("@")
fun getUserLogin(): String =
if (isEmailValid()) {
input.substringBefore("@")
} else {
""
}
}
推薦閱讀
- OpenCV實例精解
- C#程序設計(慕課版)
- 數據結構(Java語言描述)
- 青少年美育趣味課堂:XMind思維導圖制作
- Hands-On Microservices with Kotlin
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- Go并發編程實戰
- WordPress 4.0 Site Blueprints(Second Edition)
- 速學Python:程序設計從入門到進階
- Beginning C++ Game Programming
- GitHub入門與實踐
- Python期貨量化交易實戰
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- 深入分析GCC
- Mastering Drupal 8