strlength
字符串长度
说明
示例
字符串标量中的字符数
使用双引号创建一个字符串。结果是 1×1 字符串数组或字符串标量。
str = "Hello, World"
str = "Hello, World"
返回 str
中的字符数。
L = strlength(str)
L = 12
字符串数组中每个字符串的长度
使用 []
运算符创建字符串数组。str
是一个 2×3 字符串数组,其中包含六个字符串。
str = ["Amis","Chekhov","Joyce";"Stein","","Proust"]
str = 2x3 string
"Amis" "Chekhov" "Joyce"
"Stein" "" "Proust"
计算 str
中每个字符串的长度。使用 strlength
而非 length
来确定字符串数组的每个元素中的字符数量。
L = strlength(str)
L = 2×3
4 7 5
5 0 6
字符向量中的字符数
创建字符向量。要返回字符向量中的字符数,请使用 strlength
函数。
chr = 'The rain in Spain.'
chr = 'The rain in Spain.'
L = strlength(chr)
L = 18
输入参数
str
— 输入文本
字符串数组 | 字符向量 | 字符向量元胞数组
输入文本,指定为字符串数组、字符向量或字符向量元胞数组。
提示
要计算
str
的最大数组维度的长度,请使用length
函数,而不是strlength
。
算法
strlength
计算文本中的代码单元数。代码单元是字符编码系统的编码字符的位序列。在某些字符编码(如 UTF-16)中,有一些字符使用多个代码单元进行编码。
如果您有包含此类字符的字符串或字符向量,则代码单元数大于字符数。
当 C
是字符向量时,length(C)
也返回代码单元数。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2016b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)