How to replace any number of repeating characters in a string or character array

I have Evil input text from which I need to extract tabular data for csv output.
The principle challenge is removing any number of the repeating .... character, while not removing single instances of a period.
I'd like to replace the repeating character with a comma so that the text can be turned into a CSV-style output. Note that there are other commas also present that should remain.
Here's an example.
EVIL TEXT INPUT:
Riots, Tips and Other Cleverness:................................$49,000.21
Submission Flavor:.............................................Original document
REQUIRED CLEAN CSV OUTPUT:
'Riots, Tips and Other Cleverness',49000.21
'Submission Flavor','Original document'

 채택된 답변

Something like this
str = fileread('test.txt');
new_str = regexprep(str, ':\.{2,}', ',')
Result
new_str =
'Riots, Tips and Other Cleverness,$49,000.21
Submission Flavor,Original document'

추가 답변 (1개)

CdC
CdC 2020년 6월 2일
Found another approach that works better in this context:
test = 'Riots, Tips and Other Cleverness:................................$49,000.21';
C = strsplit(test,'..'); % >> cell array ans = {'Riots, Tips and Other Cleverness:'} {'$49,000.21'}

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

CdC
2020년 5월 31일

답변:

CdC
2020년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by