This has GOT to be an encoding problem but I just can't see how to
work around it right now.
I'm grabbing all the text out of a multiline RichTextBox into a
variable Eg:-
$r = $RichTextBox2.Text
Where in the RichTextbox itself the text looks like
line 1 from richtextbox
line 2 from richtextbox
line 3 from richtextbox
Now, when I try to add-content to a .txt with -value $r
the .txt looks like:-
line1 from richtextbox[]line2 from richtextbox[]line 3 from
richtextbox[]
I've tried using out-file to -append the content to the .txt so that I
can use the -encoding ASCII parameter
but it yields exactly the same result. :-(
When I look at the raw hex I see that there is a 00 0A 00 between the
lines, that is, between the x in box and the l in line.
Any suggestions as to how I could render this in a .txt accurately?
Cheers,
Stuart
PS - I note that if I copy the lines out of .the txt and paste back
into the richtextbox the formatting is perfect, which I suppose is to
be expected.
Eg back to:-
line 1 from richtextbox
line 2 from richtextbox
line 3 from richtextbox
Would you mind providing more of your code? You may get help more
quickly that way...
Marco
--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
Hi Marco,
Sorry I should have included a lot more code in my post.
Actually I think I've found a workaround. Using a standard textbox
does not produce the same undesirable effect.
I wonder what the differences are between them..? Anyway I'm happy
again now :-))
Thanks,
Stuart
Stuart,
If you still want to use a RichTextBox, both of the following
approaches work just fine for me:
$textbox = New-Object System.Windows.Forms.RichTextBox
$textbox.text = @"
line one
line two
line three
"@
# 1
$textbox.Lines |
Foreach-Object { Add-Content -Path text.txt -Value $_ }
# 2
$text = [string]::Join( "`r`n", $textbox.Lines )
Add-Content -Path text.txt -Value $text
Jeff
Thanks for that :-)
Tried #1 and it works perfectly here too. I've saved both methods for
future reference.
At the moment the Textbox is doing everything I need but if I have to
revert to a RichTextBox I'll be happier about it.
Cheers,
Stuart