# Linebreak issue with clr strings manipulated by Ruby code

**URL:** <https://www.ruby-forum.com/t/linebreak-issue-with-clr-strings-manipulated-by-ruby-code/203706>\
**Category:** IronRuby\
**Created:** [February 25, 2011, 1:46pm UTC](https://www.ruby-forum.com/t/linebreak-issue-with-clr-strings-manipulated-by-ruby-code/203706 "2011-02-25T13:46:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 25, 2011, 1:46pm UTC](https://www.ruby-forum.com/t/linebreak-issue-with-clr-strings-manipulated-by-ruby-code/203706/1 "2011-02-25T13:46:45Z")

</div>

Hi, guys. Sorry if I am posting this in the wrong place, but I need  
some kind of direction here.

I isolated my problem in the following UnitTest in Visual Basic:

\<TestMethod()\>  
Public Sub LineBreakProblem()  
Const SCRIPT = “print System::String.Format(‘Line1{0}Line2’,  
System::Environment.NewLine)”

```
Dim engine = IronRuby.Ruby.CreateEngine()
Dim stream = New IO.MemoryStream
Dim writer = New IO.StreamWriter(stream)
engine.Runtime.IO.SetOutput(stream, writer)
Dim source = engine.CreateScriptSourceFromString(SCRIPT, "Script",

```

Microsoft.Scripting.SourceCodeKind.File)  
source.Execute()

```
writer.Flush()
stream.Position = 0
Dim actual = (New IO.StreamReader(stream)).ReadToEnd()

Dim expected = String.Format("Line1{0}Line2", Environment.NewLine)

Assert.AreEqual(expected, actual)

```

End Sub

As you can see, i am running this Ruby code:

print System::String.Format(‘Line1{0}Line2’,  
System::Environment.NewLine)

And then I am using the engine.Runtime.IO.SetOutput to get back the  
result generated by the “print” statement. System.Environment.NewLine  
returns the char combination CR + LF.

The “expected” variable will contain: “Line1” + CR + LF + “Line2”.  
The “actual” variable receive the value “Line1” + CR + LF + CR + LF +  
“Line2”

Seems that all the linebreaks are doubled when using the CLR string  
with the “print” statement.

Any suggestion that you can give me to resolve or work around this  
problem will be much appreciated.

---

<div class="post-metadata">

**Author:** ![Aldinei\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f07891/32.png) [@Aldinei\_S](https://www.ruby-forum.com/u/Aldinei_S)\
**Post date:** [March 4, 2011, 12:38am UTC](https://www.ruby-forum.com/t/linebreak-issue-with-clr-strings-manipulated-by-ruby-code/203706/2 "2011-03-04T00:38:39Z")

</div>

Hi, sorry again, but is anyone seeing this message?

I coudnt get any response about this, either here or in the Codeplex  
issue tracker.

2011/2/25 Aldinei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Aldinei\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f07891/32.png) [@Aldinei\_S](https://www.ruby-forum.com/u/Aldinei_S)\
**Post date:** [March 4, 2011, 10:33pm UTC](https://www.ruby-forum.com/t/linebreak-issue-with-clr-strings-manipulated-by-ruby-code/203706/3 "2011-03-04T22:33:25Z")

</div>

Yes, I can reproduce this. I’ll look into it. Have you opened a bug?  
I’ll follow up there.  
~Jimmy

On Thu, Mar 3, 2011 at 6:11 PM, Aldinei S.

---

<div class="post-metadata">

**Author:** ![Aldinei\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f07891/32.png) [@Aldinei\_S](https://www.ruby-forum.com/u/Aldinei_S)\
**Post date:** [March 7, 2011, 12:29pm UTC](https://www.ruby-forum.com/t/linebreak-issue-with-clr-strings-manipulated-by-ruby-code/203706/4 "2011-03-07T12:29:59Z")

</div>

Yes, i created the issue #5836.

Thank you very much.

2011/3/4 Jimmy S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
