Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copy text from RichTextBox into .txt problem

419 views
Skip to first unread message

Kryten

unread,
Aug 19, 2008, 7:21:58 AM8/19/08
to
Hi,

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


Marco Shaw [MVP]

unread,
Aug 19, 2008, 9:59:08 AM8/19/08
to
Kryten wrote:
> Hi,
>
> 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

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

Kryten

unread,
Aug 19, 2008, 12:12:52 PM8/19/08
to
> Would you mind providing more of your code?  You may get help more
> quickly that way...
>
> Marco
>
> --
> *Microsoft MVP - Windows Server - Admin Frameworkshttps://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

Jeff

unread,
Aug 19, 2008, 11:32:49 PM8/19/08
to

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

Kryten

unread,
Aug 20, 2008, 3:21:45 AM8/20/08
to
Hi 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

0 new messages