A string with several lines

  • Follow


Hi,

In Java you can use "\n" as a symbol for a new line in a text string.
How do you this in rexx ?

I do it like this :

text = "This is line 1"d2c(10)"This is line 2"
say text

Can I do this in a simpler and nicer way ?

Thanks,

�smund
0
Reply joppe 6/4/2006 4:19:21 PM

joppe ha escrito:

> Hi,
>
> In Java you can use "\n" as a symbol for a new line in a text string.
> How do you this in rexx ?

  REXX (and Object REXX) hasn't scape sequences.

> text = "This is line 1"d2c(10)"This is line 2"
> say text
>
> Can I do this in a simpler and nicer way ?

  eol = d2c(10) /* or eol = '0a'x */
  text = "This is line 1" || eol || "This is line 2"
  say text

  Also you can make a special function for this purpose (and you can
add other scape sequences like \t):

  text = scape("This is line 1\nThis is line 2")
  say text
  exit

  scape: procedure
    return changestr('\n', arg(1), '0a'x)

  This is valid only for UNIX-like (Linux, BeOS...) systems: eol =
'0a'x (linefeed). In Mac systems: eol = '0d'x (carriage return). In
DOS-like systems (DOS, Windows, OS/2): eol = '0d0a'x. (The scape
sequence "\n" can be one of this options.)
  In Object REXX there are another way, but this is other story.

  Best regards:

  Salvador Parra Camacho.

0
Reply Salvador 6/4/2006 4:53:20 PM


joppe wrote:
> In Java you can use "\n" as a symbol for a new line in a text string.
> How do you this in rexx ?
> 
> I do it like this :
> 
> text = "This is line 1"d2c(10)"This is line 2"
> say text
> 
> Can I do this in a simpler and nicer way ?

As Salvador suggests you can do this more tidily, but perhaps you should 
look at why you want to do this in the first place. If you are building 
multi-line output for single say later, perhaps you should do one of the 
following instead:

a) Use say on each piece, e.g.

say "This is line 1"
say "This is line 2"

b) Build a stem and say them later, e.g.

text.1 = "This is line 1"
text.2 = "This is line 2"
text.0 = 2

....

do i = 1 to text.0
   say text.i
end

Both of these have the advantage of being "nicer" and platform 
independant too. Also, both these techniques will work if you write a 
stream using the lineout function instead of using say.

(Or, to put it another way, don't try to write Java in REXX!)

Graham.
0
Reply Graham 6/4/2006 5:24:04 PM

On 04.06.06 18:53, Salvador Parra Camacho wrote:

>   eol = d2c(10) /* or eol = '0a'x */
>   text = "This is line 1" || eol || "This is line 2"
>   say text

Please note, that REXX provides automatic concatenation of strings.
IMO, the following equivalent line is much better readable:

   text = "This is line 1"eol"This is line 2"

or as an alternative, what I prefer the most:

   text = ''
   text = text"This is line 1"eol
   text = text"This is line 2"

-- 
Andreas Schnellbacher
0
Reply Andreas 6/4/2006 6:28:38 PM

Andreas Schnellbacher ha escrito:

> Please note, that REXX provides automatic concatenation of strings.

  Yes, I know it. :)

> IMO, the following equivalent line is much better readable:
>
>    text = "This is line 1"eol"This is line 2"

  I prefer one method or other depending on the day of the week. ;)

  Curiously, PPWizard has problems with implicit concatenation and
Dennis recommends explicit concatenation in REXX code of PPWizard
macros.

> or as an alternative, what I prefer the most:
>
>    text = ''
>    text = text"This is line 1"eol
>    text = text"This is line 2"

   What about the following alternative?

      text = '' ||,
                "This is line 1"eol ||,
                "This is line 2"

   Best regards:

   Salvador Parra Camacho

0
Reply Salvador 6/4/2006 7:36:06 PM

Salvador Parra Camacho wrote:

> joppe ha escrito:
> 
> 
>>Hi,
>>
>>In Java you can use "\n" as a symbol for a new line in a text string.
>>How do you this in rexx ?
> 
> 
>   REXX (and Object REXX) hasn't scape sequences.

Anyone know if the Arexx BIF will do '\r', etc. as they did on the Amiga?
0
Reply Eric 6/4/2006 11:22:13 PM

In
Message-ID:<1149449766.920985.128580@h76g2000cwa.googlegroups.com>,
"Salvador Parra Camacho" <sparrac@gmail.com> wrote: 

>> Please note, that REXX provides automatic concatenation of strings.
>
>  Yes, I know it. :)
>
>> IMO, the following equivalent line is much better readable:
>>
>>    text = "This is line 1"eol"This is line 2"
>
>  I prefer one method or other depending on the day of the week. ;)

     Yes.  Here we're getting into preferences because both are
correct.

     My preference is Salvador's origninal:
> text = "This is line 1" || eol || "This is line 2"

     When I see text on both sides of a quote mark, it takes time
to parse out (mentally) which is being quoted and which is outside
the quotes.  Using concatenation marks makes it obvious.  I do use
the automatic concatenation when I want the automatic space
between.

     Speaking of style, though, I've begun to use single quotes
instead of double.  That way, my programs can be fairly
consistent, even when I need to include the double-quotes that
delimit filenames which contain spaces.

-- 
Arthur T. - ar23hur "at" intergate "dot" com
Looking for a good MVS systems programmer position
0
Reply Arthur 6/5/2006 3:02:13 AM

Hi everyone !

Thanks for all the tips - and quick response !

Best regrads �smund


joppe wrote:
> Hi,
> 
> In Java you can use "\n" as a symbol for a new line in a text string.
> How do you this in rexx ?
> 
> I do it like this :
> 
> text = "This is line 1"d2c(10)"This is line 2"
> say text
> 
> Can I do this in a simpler and nicer way ?
> 
> Thanks,
> 
> �smund
0
Reply joppe 6/5/2006 9:19:41 AM

7 Replies
244 Views

(page loaded in 0.463 seconds)

Similiar Articles:













7/28/2012 7:22:02 PM


Reply: