help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to strip carriage return or linefeed from a string


From: Andy Buckle
Subject: Re: how to strip carriage return or linefeed from a string
Date: Tue, 4 Dec 2012 12:41:44 +0000




On 4 December 2012 12:22, Andy Buckle <address@hidden> wrote:



On 4 December 2012 09:59, Sergei Steshenko <address@hidden> wrote:




----- Original Message -----
> From: Hugo Coolens <address@hidden>
> To: address@hidden
> Cc:
> Sent: Tuesday, December 4, 2012 11:52 AM
> Subject: how to strip carriage return or linefeed from a string
>
> I'm looking for a way to put two strings one representing a current
> and one representing a voltage next to each other in a file. The
> following is a code fragment:
>
> usbtmc_write(fd,"MEAS:CURR?");
> resultcurr = char(usbtmc_read(fd,readbytes))
> strrep(resultcurr,'\n','')
> usbtmc_write(fd,"MEAS:VOLT?");
> resultvolt = char(usbtmc_read(fd,readbytes))
> fprintf(file_id, '%s' , [resultcurr resultvolt])
>
> I now get the following output in my outputfile
> 0.0249128
> 0.252767
>
> But I want:
> 0.0249128 0.252767
>
> Can anyone here solve this?
>
> thanks
> Hugo
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Well, there is a number of ways.

You can delete the last character in a string. e.g. this way:

foo = bar(1:end-1);
.

You can use regular _expression_.

Regards,
  Sergei.

A couple of alternatives. These just show newline removal. Repeat for carriage return. For anything cleverer, you probably want regular expressions.

>s="123\n124"
s = 123
124
>s1=s
s1 = 123
124
>s1(s1=="\n")=[]
s1 = 123124
>s1=s
s1 = 123
124
>s1=strrep(s1,"\n","")
s1 = 123124
>

--
/* andy buckle */

I could not recall how to do it the regex way. I revised. I have stripped the chars here, you probably want to replace them with spaces.

>regexprep("123\n456",'\r|\n',"")
ans = 123456
>regexprep("123\r\n456",'\r|\n',"")
ans = 123456


--
/* andy buckle */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]