CStr2String

版本 1.2.0.0 (8.5 KB) 作者: Jan
Fast concatenation of cell strings to a string as C-Mex
2.0K 次下载
更新时间 2010/11/28

查看许可证

Concatenate strings of a cell string

This equals CAT(2, C{:}) and SPRINTF('%s', C{:}), but is remarkably faster,
because the output is pre-allocated.

Str = CStr2String(CStr, Separator, Trail)
INPUT:
CStr: Cell string of any size. All not-empty cell elements must be
strings ([1 x N] CHAR vectors).
Separator: String, which is appended after each string of CStr.
This is thought to emulate: "sprintf(['%s', Sep], CStr{:})".
Optional, default: ''.
Trail: String or logical flag. For 'noTrail' or FALSE the trailing
separator is omitted. Optional, default: 'Trail'.

OUTPUT:
Str: [1 x M] CHAR vector, concatenated strings of the input.

EXAMPLES:
Write a cell string to a file:
Slow: fprintf(FID, '%s\n', CStr{:});
Fast: fwrite(FID, CStr2String(CStr, char(10)), 'uchar');
A comma-separated list;
CStr = {'First', 'Second', 'Third'});
Str = CStr2String(CStr, ', ', 'noTrail');
>> 'First, Second, Third'

COMPILATION:
mex -O CStr2String.c
or download from: http://www.n-simon.de/mex
Please run the unit-test uTest_CStr2String after compiling!

Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32bit
Compiler: LCC2.4/3.8, BCC5.5, OWC1.8, MSVC2008
Assumed Compatibility: higher Matlab versions, Mac, Linux, 64bit

See also: HORZCAT, CAT, SPRINTF, STRCAT.
FEX: http://www.mathworks.com/matlabcentral/fileexchange/28916-cell2vec

引用格式

Jan (2024). CStr2String (https://www.mathworks.com/matlabcentral/fileexchange/26077-cstr2string), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.2.0.0

3rd input to suppress trailing separator

1.1.0.0

The test function uses more realistic test data now. This reduces the displayed speed-up.

1.0.0.0