Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
strip line feeds, white spaces, control character

Subject: strip line feeds, white spaces, control character

From: sarvat

Date: 8 Apr, 2008 13:53:02

Message: 1 of 5

I need to remove 1)line feeds) white space and blank spaces
3) any control character from my text file (abc.txt).
I tried using 'deblank' and 'strtrim' but not much success.
Any suggestions?

abc.txt

/se/j1_en = OFF
/se/j1_ag_en = ON
/abc/j1_xyz/f0 = 0.000170
/abc/j1_xyz/f1 = 1.001234
/abc/j1_xyz/f2 = -1.234567
/abc/j2_xyz/f0 = 0.939140
/abc/j2_xyz/f1 = -0.966763

Subject: strip line feeds, white spaces, control character

From: Yuri Geshelin

Date: 8 Apr, 2008 14:04:02

Message: 2 of 5

Hi,

Here is one of the solutions. Once you have read the text
string s, do this:

indx = find(s==char(13) | s==char(10) | s==' ');
s(indx) = [];

Yuri

"sarvat " <sarvatm@yahoo.com> wrote in message
<ftftbu$2nn$1@fred.mathworks.com>...
> I need to remove 1)line feeds) white space and blank
spaces
> 3) any control character from my text file (abc.txt).
> I tried using 'deblank' and 'strtrim' but not much
success.
> Any suggestions?
>
> abc.txt
>
> /se/j1_en = OFF
> /se/j1_ag_en = ON
> /abc/j1_xyz/f0 = 0.000170
> /abc/j1_xyz/f1 = 1.001234
> /abc/j1_xyz/f2 = -1.234567
> /abc/j2_xyz/f0 = 0.939140
> /abc/j2_xyz/f1 = -0.966763

Subject: strip line feeds, white spaces, control character

From: Jos

Date: 8 Apr, 2008 21:36:27

Message: 3 of 5

"sarvat " <sarvatm@yahoo.com> wrote in message
<ftftbu$2nn$1@fred.mathworks.com>...
> I need to remove 1)line feeds) white space and blank
spaces
> 3) any control character from my text file (abc.txt).
> I tried using 'deblank' and 'strtrim' but not much
success.
> Any suggestions?
>
> abc.txt
>
> /se/j1_en = OFF
> /se/j1_ag_en = ON
> /abc/j1_xyz/f0 = 0.000170
> /abc/j1_xyz/f1 = 1.001234
> /abc/j1_xyz/f2 = -1.234567
> /abc/j2_xyz/f0 = 0.939140
> /abc/j2_xyz/f1 = -0.966763


This offers an approach:

s = textread('abc.txt','%s')
LongString = cat(2,s{:}) ;

You could use regexprep in between to remove certain
character sequences, like in

s = regexprep(s,'(/abc)','')

hth
Jos

Subject: strip line feeds, white spaces, control character

From: sarvat

Date: 9 Apr, 2008 09:01:03

Message: 4 of 5

thanks yuri,
"Yuri Geshelin" <geshelin@hotmail.com> wrote in message
<ftfu0i$5vb$1@fred.mathworks.com>...
> Hi,
>
> Here is one of the solutions. Once you have read the text
> string s, do this:
>
> indx = find(s==char(13) | s==char(10) | s==' ');
> s(indx) = [];
>
> Yuri
>
> "sarvat " <sarvatm@yahoo.com> wrote in message
> <ftftbu$2nn$1@fred.mathworks.com>...
> > I need to remove 1)line feeds) white space and blank
> spaces
> > 3) any control character from my text file (abc.txt).
> > I tried using 'deblank' and 'strtrim' but not much
> success.
> > Any suggestions?
> >
> > abc.txt
> >
> > /se/j1_en = OFF
> > /se/j1_ag_en = ON
> > /abc/j1_xyz/f0 = 0.000170
> > /abc/j1_xyz/f1 = 1.001234
> > /abc/j1_xyz/f2 = -1.234567
> > /abc/j2_xyz/f0 = 0.939140
> > /abc/j2_xyz/f1 = -0.966763
>

Subject: strip line feeds, white spaces, control character

From: sarvat

Date: 11 Apr, 2008 14:29:02

Message: 5 of 5

thanks jos,
this does the job, much appreciated.
regards
sarvat

"Jos " <DELjos@jasenDEL.nl> wrote in message <ftgogr$965
$1@fred.mathworks.com>...
> "sarvat " <sarvatm@yahoo.com> wrote in message
> <ftftbu$2nn$1@fred.mathworks.com>...
> > I need to remove 1)line feeds) white space and blank
> spaces
> > 3) any control character from my text file (abc.txt).
> > I tried using 'deblank' and 'strtrim' but not much
> success.
> > Any suggestions?
> >
> > abc.txt
> >
> > /se/j1_en = OFF
> > /se/j1_ag_en = ON
> > /abc/j1_xyz/f0 = 0.000170
> > /abc/j1_xyz/f1 = 1.001234
> > /abc/j1_xyz/f2 = -1.234567
> > /abc/j2_xyz/f0 = 0.939140
> > /abc/j2_xyz/f1 = -0.966763
>
>
> This offers an approach:
>
> s = textread('abc.txt','%s')
> LongString = cat(2,s{:}) ;
>
> You could use regexprep in between to remove certain
> character sequences, like in
>
> s = regexprep(s,'(/abc)','')
>
> hth
> Jos

Tags for this Thread

No tags are associated with this thread.

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.

Contact us