当前位置: 首页 > news >正文

处理空输入踩的坑

处理一个外部传入的用户输入的时候,一开始只想着处理null,用"?.let{}"的模式处理。结果发现结果异常。
打断点发现传入值不是空,而是""
由此发现kotlin处理空string的两个函数:

isEmpty()

The isEmpty() function returns true only if the string has a length of zero.

  • "" is empty.
  • " " is not empty.
  • "\t\n" is not empty.
  • "hello" is not empty.

Essentially, isEmpty() performs a very literal check: are there any characters in this string at all?

isBlank()

The isBlank() function is more nuanced. It returns true if the string is empty OR if it consists only of whitespace characters (spaces, tabs, newlines, etc.).

  • "" is blank.
  • " " is blank.
  • "\t\n" is blank.
  • "hello" is not blank.

isBlank() checks if there is any meaningful, non-whitespace content in the string.

http://www.hskmm.com/?act=detail&tid=37661

相关文章:

  • latex输入公式
  • 【为美好CTF献上祝福】 New Star 2025 逆向笔记
  • XXL-JOB(5)
  • 蛋白表达原理与关键要素解析
  • Ramanujan Master Theorem
  • 顾雅南的声音美化课堂
  • C++案例 自定义数组
  • 【周记】2025.10.13~2025.10.19
  • 背包
  • 10.23《程序员修炼之道 从小工到专家》第二章 注重实效的途径 - GENGAR
  • 玩转单片机之智能车小露——LED闪烁实战
  • ord() 函数
  • 2025.10.23总结 - A
  • 大模型 | VLA 初识及在自动驾驶场景中的应用
  • ExPRT.AI如何预测下一个将被利用的漏洞
  • Redis中的分布式锁之SETNX底层实现
  • 攻击模拟
  • 2025家纺摄影公司推荐,南通鼎尚摄影专注产品视觉呈现
  • AI元人文构想的跨学科研究:技术实现与人文影响分析——对自由与责任的再框架化(DeepSeek基于Ai元人文系列文章研究)
  • Python---简易编程解决工作问题
  • 日总结 16
  • 比赛题解 总结
  • DM8 安装包 for linux_x86
  • MPK(Mirage Persistent Kernel)源码笔记(1)--- 基础原理
  • 模拟can通信
  • 解题报告-拯救计划(概率 DP)
  • 日志分析-IIS日志分析
  • Min_25 筛
  • 解码Linux文件IO之库的制作与应用
  • 20251023 正睿二十连测