Thread Subject: Replacing spaces with underscores in Text

Subject: Replacing spaces with underscores in Text

From: sushma sharma

Date: 12 Feb, 2008 15:34:01

Message: 1 of 5

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

Subject: Replacing spaces with underscores in Text

From: Richard Quist

Date: 12 Feb, 2008 15:47:30

Message: 2 of 5

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

From: Thomas Pieper

Date: 12 Feb, 2008 15:51:02

Message: 3 of 5

"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

From: Ben

Date: 12 Feb, 2008 15:52:01

Message: 4 of 5

"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

From: sushma sharma

Date: 12 Feb, 2008 16:00:21

Message: 5 of 5

thank you!


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
text manipulation replace space sushma sharma 12 Feb, 2008 10:35:04
rssFeed for this Thread

Public Submission Policy

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.

Contact us at files@mathworks.com