Opposite to horzcat?

1 次查看(过去 30 天)
nilsotto
nilsotto 2016-3-7
评论: nilsotto 2016-3-7
How do I subtract a part of a string? i.e the opposite functionality of horzcat. Say that I have a string = 'textstring' and I want to subtract string so that I get string2 = 'text'.
  1 个评论
Stephen23
Stephen23 2016-3-7
编辑:Stephen23 2016-3-7
Keep in mind that there is no such thing as the opposite of concatenation given just one string as an input, because by concatenating you lose information (i.e. the lengths of the parts). The only way to truly perform the opposite operation to concatenation requires that you store the part lengths as well as the concatenated string.

请先登录,再进行评论。

回答(3 个)

Guillaume
Guillaume 2016-3-7
Note that if what you want to do is just separate a filename into its different components, you can use fileparts:
[~, name, extension] = fileparts('kalle.mat')

Walter Roberson
Walter Roberson 2016-3-7
Strings are row vector of char, so index the vectors.
string2 = string(1:4);
  3 个评论
Torsten
Torsten 2016-3-7
string2 = string(1:end-characters_to_be_removed_from_the_end);
Best wishes
Torsten.
nilsotto
nilsotto 2016-3-7
Many thanks Torsten!

请先登录,再进行评论。


Torsten
Torsten 2016-3-7
string2 = string(1:4);
Best wishes
Torsten.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by