当前位置: 首页 > 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.zskr.cn/news/28751.html

相关文章:

  • 66页实验题
  • 简单云计算算法--20251023
  • latex输入公式
  • 10.23《程序员修炼之道 从小工到专家》第二章 注重实效的途径 - GENGAR
  • 树状数组求逆序对
  • ExPRT.AI如何预测下一个将被利用的漏洞
  • AI元人文构想的跨学科研究:技术实现与人文影响分析——对自由与责任的再框架化(DeepSeek基于Ai元人文系列文章研究)
  • 日总结 16
  • 解码Linux文件IO之库的制作与应用
  • 20251023 正睿二十连测
  • 日志分析-IIS日志分析
  • Visual Studio 插件 - 喝水提醒 - 指南
  • 10/23
  • 玛哈特十一辊矫平机:把金属板送进“11 次节拍器” - 教程
  • 第3天(中等题+简单题 数组、滑动窗口)
  • ollama v0.12.2 版本更新详解:Qwen3 架构协助、Multi-Regex 分词器、新引擎前后缀匹配等功能升级
  • MySQL主从同步读写分离
  • SwiftUI NavigatorStack 导航容器
  • 深入解析:【仿生机器人】基于 GPT-SoVITS 的 发声器
  • PCL1.12 解决memory.h中EIGEN处中断问题
  • 20251023
  • Java常用机制 - SPI机制详解
  • 2025.10.23——2绿2蓝
  • 采用opencv来识别信用卡的号码
  • 精读《C++20设计模式》:重新理解设计模式系列 - 详解
  • 《程序员修炼之道:从小工到专家》阅读笔记1
  • ski 和 db 模块的通信
  • rocky10自己手动换源
  • layui时间与日期选择器,时间范围查询数据,后端springboot
  • 轻量级图片信息解析程序