Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

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

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics