\n equivalent?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

\n equivalent?

Paul DeBruicker
Hi -

What Character or String is equal to \n in C or Python?  Thanks


Paul
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

Enrico Schwass-2
Paul DeBruicker <[hidden email]> writes:

there are methods like cr or lf in class Character

hth
Enno

> Hi -
>
> What Character or String is equal to \n in C or Python?  Thanks
>
>
> Paul
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

Michael van der Gulik-2
In reply to this post by Paul DeBruicker


On Fri, Jul 31, 2009 at 8:48 AM, Paul DeBruicker <[hidden email]> wrote:
Hi -

What Character or String is equal to \n in C or Python?  Thanks


I remember wondering about this when I was first learning Smalltalk too.

You do stuff like:

s := WriteStream on: (String new: 100).
s nextPutAll: 'Hello World'. "Write a string"
s nextPut: $!.             "Write a single character"
s cr.             "Write a newline character"

It's a bit wordy, but I think streams deserve a lot more credit than programmers give them.

If you're doing String concatenation:

myString := 'Hello, World!', String cr.

Alternatively, this is also valid code:

myString := 'This
is
a
multi-line
String!
'.

Gulik.

--
http://gulik.pbwiki.com/

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

cdavidshaffer
Michael van der Gulik wrote:

>
>
> On Fri, Jul 31, 2009 at 8:48 AM, Paul DeBruicker <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi -
>
>     What Character or String is equal to \n in C or Python?  Thanks
>
>
>
> I remember wondering about this when I was first learning Smalltalk too.
>
> You do stuff like:
>
> s := WriteStream on: (String new: 100).
> s nextPutAll: 'Hello World'. "Write a string"
> s nextPut: $!.             "Write a single character"
> s cr.             "Write a newline character"
>
> It's a bit wordy, but I think streams deserve a lot more credit than
> programmers give them.
>
> If you're doing String concatenation:
>
> myString := 'Hello, World!', String cr.
>
> Alternatively, this is also valid code:
>
> myString := 'This
> is
> a
> multi-line
> String!
> '.
>
Great summary.  I'll add:

'this\is\a\string' withCRs

which produces
this
is
a
string

If you look at the source code for withCRs you can probably see how easy
it would be to write something more to your liking.

David


David

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

Paul DeBruicker
Hi,

This is all very interesting.

So
'Character cr asciiValue' is 13
'Character lf asciiValue' is 10

and ascii value of the \n character in Python is

>>>  ord('\n')
10


So I want to use 'String lf' inplace of a \n in Python during string
concatenation.


Thanks

Paul




On Sun, Aug 2, 2009 at 2:39 PM, C. David Shaffer<[hidden email]> wrote:

> Michael van der Gulik wrote:
>>
>>
>> On Fri, Jul 31, 2009 at 8:48 AM, Paul DeBruicker <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>    Hi -
>>
>>    What Character or String is equal to \n in C or Python?  Thanks
>>
>>
>>
>> I remember wondering about this when I was first learning Smalltalk too.
>>
>> You do stuff like:
>>
>> s := WriteStream on: (String new: 100).
>> s nextPutAll: 'Hello World'. "Write a string"
>> s nextPut: $!.             "Write a single character"
>> s cr.             "Write a newline character"
>>
>> It's a bit wordy, but I think streams deserve a lot more credit than
>> programmers give them.
>>
>> If you're doing String concatenation:
>>
>> myString := 'Hello, World!', String cr.
>>
>> Alternatively, this is also valid code:
>>
>> myString := 'This
>> is
>> a
>> multi-line
>> String!
>> '.
>>
> Great summary.  I'll add:
>
> 'this\is\a\string' withCRs
>
> which produces
> this
> is
> a
> string
>
> If you look at the source code for withCRs you can probably see how easy it
> would be to write something more to your liking.
>
> David
>
>
> David
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

Bert Freudenberg
On 02.08.2009, at 23:20, Paul DeBruicker wrote:

> So
> 'Character cr asciiValue' is 13
> 'Character lf asciiValue' is 10
>
> and ascii value of the \n character in Python is
>
>>>> ord('\n')
> 10
>
>
> So I want to use 'String lf' inplace of a \n in Python during string
> concatenation.


#lf is rarely used in Squeak code. Typically we use #cr. E.g., if you  
want a line break while writing to the Transcript you would send #cr.  
Same if you want a line break in a text file. Rather than switching  
between #cr, #lf, and #crlf depending on the platform being a Mac,  
Unix, or Windows, we only use #cr and rather set the stream to the  
right line end conversion method.

- Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

Michael van der Gulik-2
In reply to this post by Paul DeBruicker


On Mon, Aug 3, 2009 at 9:20 AM, Paul DeBruicker <[hidden email]> wrote:
Hi,

This is all very interesting.

So
'Character cr asciiValue' is 13
'Character lf asciiValue' is 10

This gets complicated.

See http://en.wikipedia.org/wiki/Newline for a better summary than I could write. This should be required reading for anybody working with multi-platform text files.

Perhaps we need Stream>>newline or something?

Squeak follows the Macintosh OS9 convention (refer Wikipedia article above under "Representation"). Arguably we should perhaps start using CR+LF like Internet protocols do. Or perhaps the Unicode suggestion of... er... yea, one of the options shown on that page.

Gulik.

--
http://gulik.pbwiki.com/

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: \n equivalent?

Paul DeBruicker
In reply to this post by Bert Freudenberg
Ok so for smalltalk specific code I'll use cr

The reason I needed to know is that I need to make an HMAC-SHA256 hash  
of a multiline string and submit it to a third party for processing.    
In their java and python examples they concatenated in a \n to form  
the multiple line string. At the time I asked, what I was calculating  
was incorrect so as  part of trying to figure out where I had the  
calculation wrong I wanted to make sure I was using the proper  
substitute

Thanks again for the help

Paul


On Aug 2, 2009, at 5:51 PM, Bert Freudenberg <[hidden email]>  
wrote:

> On 02.08.2009, at 23:20, Paul DeBruicker wrote:
>
>> So
>> 'Character cr asciiValue' is 13
>> 'Character lf asciiValue' is 10
>>
>> and ascii value of the \n character in Python is
>>
>>>>> ord('\n')
>> 10
>>
>>
>> So I want to use 'String lf' inplace of a \n in Python during string
>> concatenation.
>
>
> #lf is rarely used in Squeak code. Typically we use #cr. E.g., if  
> you want a line break while writing to the Transcript you would send  
> #cr. Same if you want a line break in a text file. Rather than  
> switching between #cr, #lf, and #crlf depending on the platform  
> being a Mac, Unix, or Windows, we only use #cr and rather set the  
> stream to the right line end conversion method.
>
> - Bert -
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners