strtrim
从字符串中删除前导和尾随空白
说明
示例
从字符向量中删除前导空白
创建用空白和制表符作为前导空白的字符向量。
chr = sprintf(' \t Remove leading whitespace')
chr = ' Remove leading whitespace'
删除前导制表符和空白。
newChr = strtrim(chr)
newChr = 'Remove leading whitespace'
strtrim
删除前导空白字符,但不会删除其他字符之间的空白。
从字符串数组中删除前导和尾随空格
创建一个字符串数组。
str = [" Gemini "," Apollo "; " ISS "," Skylab "]
str = 2x2 string
" Gemini " " Apollo "
" ISS " " Skylab "
使用 strtrim
函数删除前导和尾部空白。
newStr = strtrim(str)
newStr = 2x2 string
"Gemini" "Apollo"
"ISS" "Skylab"
从元胞数组中删除前导和尾随空白
从元胞数组的所有字符向量中删除前导和尾随空白,并显示它们。
chr = {' Trim leading whitespace'; 'Trim trailing whitespace '}
chr = 2x1 cell
{' Trim leading whitespace' }
{'Trim trailing whitespace '}
newChr = strtrim(chr)
newChr = 2x1 cell
{'Trim leading whitespace' }
{'Trim trailing whitespace'}
保留不间断空白字符
创建一个用不间断空白字符 char(160)
作为尾随空白字符的字符向量。
chr = ' Keep nonbreaking space'; chr = [chr char(160) ' '];
在 | 符号之间显示 chr
,以显示前导和尾随空白。
['|' chr '|']
ans = '| Keep nonbreaking space |'
删除前导和尾随空白字符。
newChr = strtrim(chr);
在 | 符号之间显示 newChr
。strtrim
将删除 newChr
末尾的空白字符,但会保留不间断空白。
['|' newChr '|']
ans = '|Keep nonbreaking space |'
输入参数
str
— 输入文本
字符数组 | 字符数组的元胞数组 | 字符串数组
输入文本,指定为字符数组、字符数组元胞数组或字符串数组。
算法
strtrim
不会删除实义空白字符。
下表列出了最常见的实义空白字符及其说明。有关详细信息,请参阅空白字符。
实义空白字符 | 说明 |
---|---|
| 下一行 |
| 不间断空格 |
| 图窗空格 |
| 不间断窄空格 |
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
输入文本必须是字符串标量或字符数组。
输入值必须在 0-127 的范围内。
生成的代码以 1×0 字符数组的形式返回空输出。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅Run MATLAB Functions in Thread-Based Environment。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
用法说明和限制:
str
必须为字符串数组或字符向量元胞数组。
有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2006a 之前推出
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)