julia - 如何检查字符串是否为空?
问题描述
如何检查字符串是否为空?
我目前正在使用==
运营商:
julia> x = "";
julia> x == "";
true
解决方案
使用isempty
. 它更明确,更有可能针对其用例进行优化。
例如,在最新的 Julia 上:
julia> using BenchmarkTools
julia> myisempty(x::String) = x == ""
foo (generic function with 1 method)
julia> @btime myisempty("")
2.732 ns (0 allocations: 0 bytes)
true
julia> @btime myisempty("bar")
3.001 ns (0 allocations: 0 bytes)
false
julia> @btime isempty("")
1.694 ns (0 allocations: 0 bytes)
true
julia> @btime isempty("bar")
1.594 ns (0 allocations: 0 bytes)
false
推荐阅读
- angular - 需要 angular-google-maps fitBoundsAccessor 抽象类示例
- typescript - 将打字稿编译成不同的路径
- python - 如何使用 matplotlib 绘制 collections.Counter 直方图?
- c++ - 类型推理“自动”和引用调用如何工作?
- github - 我的 Travis-CI 与 GitHub 的集成失败了
- javascript - Add popover containing image in a table - Shiny
- android - 将依赖项“com.google.android.gms:play-services-location:15.0.1”添加到“com.android.support:appcompat-v7:28.0.0”后面临错误
- java - manyTomany 会出现性能问题吗?
- php - 为什么我不能在 PHP 中创建 MySQL 存储过程?
- c# - 现场测试 ASP.NET 自定义角色提供程序