sushma sharma wrote:
> hi,
>
> I have a 800x1 cell array containing text such as:
>
> RPT OK 12 R
>
> How can I replace the spaces in the text with underscores
> (i.e. _ ) ?
>
> I would like the output to be:
>
> RPT_OK_12_R
>
> Thanks!
>
> sushma
help strrep
--
Richard Quist
Software Developer
The MathWorks, Inc.
Subject: Replacing spaces with underscores in Text
"sushma sharma" <ssharma@ynospamahoo.com> wrote in message
<fose99$cba$1@fred.mathworks.com>...
> hi,
>
> I have a 800x1 cell array containing text such as:
>
> RPT OK 12 R
>
> How can I replace the spaces in the text with underscores
> (i.e. _ ) ?
>
> I would like the output to be:
>
> RPT_OK_12_R
>
> Thanks!
>
> sushma
Hi,
regexprep(a,' ','_')
should do the job.
Sincerely, Thomas
Subject: Replacing spaces with underscores in Text
"sushma sharma" <ssharma@ynospamahoo.com> wrote in message
<fose99$cba$1@fred.mathworks.com>...
> hi,
>
> I have a 800x1 cell array containing text such as:
>
> RPT OK 12 R
>
> How can I replace the spaces in the text with underscores
> (i.e. _ ) ?
>
> I would like the output to be:
>
> RPT_OK_12_R
Look at help strfun for a list of functions related to
strings. In this case you want STRREP. If your cellstr array
is called C,
C=strrep(C, ' ', '_')
will do what you want.
Subject: Replacing spaces with underscores in Text
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Disclaimer prior to use.