Hi -
What Character or String is equal to \n in C or Python? Thanks
Paul
Paul DeBruicker pdebruic@gmail.com 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 Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
On Fri, Jul 31, 2009 at 8:48 AM, Paul DeBruicker pdebruic@gmail.com 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.
Michael van der Gulik wrote:
On Fri, Jul 31, 2009 at 8:48 AM, Paul DeBruicker <pdebruic@gmail.com mailto:pdebruic@gmail.com> 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
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 Shaffercdshaffer@acm.org wrote:
Michael van der Gulik wrote:
On Fri, Jul 31, 2009 at 8:48 AM, Paul DeBruicker <pdebruic@gmail.com mailto:pdebruic@gmail.com> 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 Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
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 -
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 bert@freudenbergs.de 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 Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
On Mon, Aug 3, 2009 at 9:20 AM, Paul DeBruicker pdebruic@gmail.com 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.
beginners@lists.squeakfoundation.org