Thread Subject: Remove special characters from contents of a cell array

Subject: Remove special characters from contents of a cell array

From: the cyclist

Date: 24 Nov, 2009 14:29:21

Message: 1 of 4

I have a cell array which contains string elements, but embedded in those strings are special characters (like carriage returns) that are messing up some later processing. I can't seem to get rid of them.

I have tried doing SSCANF(..., '%s%c'), which seems to get rid of some, but not all, of the special characters. Any other ideas?

I don't need to do this particularly efficiently. It is a fairly small cell array, of only 500 elements or so. Fine to do it in a slow loop.

Subject: Remove special characters from contents of a cell array

From: Jos (10584)

Date: 24 Nov, 2009 14:54:36

Message: 2 of 4

"the cyclist" <thecyclist@gmail.com> wrote in message <hegqk1$8iu$1@fred.mathworks.com>...
> I have a cell array which contains string elements, but embedded in those strings are special characters (like carriage returns) that are messing up some later processing. I can't seem to get rid of them.
>
> I have tried doing SSCANF(..., '%s%c'), which seems to get rid of some, but not all, of the special characters. Any other ideas?
>
> I don't need to do this particularly efficiently. It is a fairly small cell array, of only 500 elements or so. Fine to do it in a slow loop.

Most special characters have ascii codes that you can replace using STRREP or even REGEXPREP:

C = {'text',sprintf('WITH\tTAB')}
C = strrep(C,char(9),'_') % tab

hth
Jos

Subject: Remove special characters from contents of a cell array

From: Branko

Date: 24 Nov, 2009 15:01:20

Message: 3 of 4

"the cyclist" <thecyclist@gmail.com> wrote in message <hegqk1$8iu$1@fred.mathworks.com>...
> I have a cell array which contains string elements, but embedded in those strings are special characters (like carriage returns) that are messing up some later processing. I can't seem to get rid of them.
>
> I have tried doing SSCANF(..., '%s%c'), which seems to get rid of some, but not all, of the special characters. Any other ideas?
>
> I don't need to do this particularly efficiently. It is a fairly small cell array, of only 500 elements or so. Fine to do it in a slow loop.

One possible solution would be using regular expression (regexp). If you show small example - of you cell array it would be more clear what exactly you are want to extract.

Branko

Subject: Remove special characters from contents of a cell array

From: the cyclist

Date: 24 Nov, 2009 18:17:23

Message: 4 of 4

"the cyclist" <thecyclist@gmail.com> wrote in message <hegqk1$8iu$1@fred.mathworks.com>...
> I have a cell array which contains string elements, but embedded in those strings are special characters (like carriage returns) that are messing up some later processing. I can't seem to get rid of them.
>
> I have tried doing SSCANF(..., '%s%c'), which seems to get rid of some, but not all, of the special characters. Any other ideas?
>
> I don't need to do this particularly efficiently. It is a fairly small cell array, of only 500 elements or so. Fine to do it in a slow loop.

Thanks for the replies. I was able to use ISSTRPROP with reasonable effectiveness.

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
regexp Branko 24 Nov, 2009 10:04:26
rssFeed for this Thread

Contact us at files@mathworks.com