I want to shorten a string.

13 次查看(过去 30 天)
I have this string that contains information about the date and the hour of the acquistion.
Start=2021-06-11T:12:32:04:122
The result I am looking for is this:
12:32:04:122

采纳的回答

Walter Roberson
Walter Roberson 2021-7-25
If it is a string() object then see extractAfter()

更多回答(1 个)

DGM
DGM 2021-7-25
编辑:DGM 2021-7-25
You can use regexp() on either strings or chars.
timestamp = 'Start=2021-06-11T:12:32:04:122';
out = regexp(timestamp,'(?<=:).*','match')
out = 1×1 cell array
{'12:32:04:122'}
Given that you probably have more than one timestamp to process, you may have to tweak things depending on whether you're dealing with a string array or a cell array of char vectors. In this case, the input is a char vector and the output is a cell array of char vectors. Consider the case where the input is a cell array of char vectors:
timestamp = 'Start=2021-06-11T:12:32:04:122';
timestamp = {timestamp; timestamp; timestamp};
out = regexp(timestamp,'(?<=:).*','match');
out = vertcat(out{:})
out = 3×1 cell array
{'12:32:04:122'} {'12:32:04:122'} {'12:32:04:122'}

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by