소스 검색

增加bool

git 2 주 전
부모
커밋
b5daf02eb3
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      src/main/kotlin/cn/qqck/kotlin/tools/String.kt

+ 5 - 0
src/main/kotlin/cn/qqck/kotlin/tools/String.kt

@@ -1,6 +1,11 @@
 package cn.qqck.kotlin.tools
 
 fun String.bytes() = this.toByteArray()
+fun String.bool(): Boolean? {
+    if (this == "1" || this == "t" || this == "T" || this == "true" || this == "True" || this == "yes" || this == "Yes") return true
+    if (this == "0" || this == "f" || this == "F" || this == "false" || this == "False" || this == "no" || this == "No") return false
+    return null
+}
 
 /**
  * 从当前字符串中获取指定子字符串前的内容。