0

I tried to get my brakets back from the wirteStream. Sadly the writeStream set two punctuation marks (apostrophes) before and after the brackets.

Could someone help me? I found the mistake for this in the class String in printOn and mainly in storeOn.

Have you an idea to solve it? I thought on RegEx... but maybe someone has another methode or solution.

| stream |
'()' printOn: (stream := '' writeStream).
stream contents = '()'.

Regards, bartak.

bartak
  • 91
  • 7

2 Answers2

3

This is because String's #printOn: explicitly calls #storeOn:

printOn: aStream 
    "Print inside string quotes, doubling inbedded quotes."

    self storeOn: aStream

You could do it the other way around:

(stream := '' writeStream) nextPutAll: '()'.
Tobias
  • 3,026
  • 20
  • 34
  • Thank you, Tobias. I want to show the trace of methods for other users here, so I listed printOn in my explanation. Next time I will show only the important method. ;-) – bartak Oct 21 '14 at 21:20
2

That's because String>>printOn: will print "a string as a string", i.e. it will be quoted again. Solution: don't use #printOn: but rather Stream>>nextPutAll: or Stream>>print:.

Clarification:

#print is supposed to be sent to the stream, not to ByteString:

'' writeStream print: '()'.

Max Leske
  • 5,007
  • 6
  • 42
  • 54