How to replace different variables with a single variable in a text file?

2 vues (au cours des 30 derniers jours)
Hello everybody! I am not so used to editing and working with .txt files in MATLAB. I am looking for ways to replace multiple set of characters like '=' , '+', '-' with any single character like '%'. I guess I need to use regexprep for this purpose, but I am not able to figure it out for the .txt file. Any help will be appreciated. Thanks
  2 commentaires
Tiasa Ghosh
Tiasa Ghosh le 15 Mai 2018
I meant if the input is a cell array, it can be worked out by specifying each cell as cell{} and replacing, but how should I do it for a .txt file with several lines?

Connectez-vous pour commenter.

Réponse acceptée

Akira Agata
Akira Agata le 15 Mai 2018
Here is a simple example on how to use regexprep to replace '=','+','-' with '%'.
strIn = 'Please replace multiple set of characters like =, +, - with %';
strOut = regexprep(strIn,'[=+-]','%');
The result becomes:
>> strOut
strOut =
'Please replace multiple set of characters like %, %, % with %'
  2 commentaires
Tiasa Ghosh
Tiasa Ghosh le 15 Mai 2018
Silly mistake on my part I used fileread first to get the inputdata. Thank you again.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by