Product, version and build: PowerShell Studio 2017 build 5.4.140
32 or 64 bit version of product: 64
Operating system: Win10 Ent.
32 or 64 bit OS: 64
PowerShell Version: 5.1
As per subject I'm working a GUI project to parse some log files for specific strings, logs in turn are generated by other PowerShell scripts with a small function which stamps the time message has been logged together with the message.
New line in the log file is handled through " `r`n", in the GUI I let the user select the folder where to look for logs, select the string to search and the ouput content to the TextBox (same behavior I've though experienced with a RichTextbox), problem is new lines are not honored and text looks inconsistent.
I've tried multiple approaches but result is always the same.
- Multiline is of course on
- I've tried disabling word wrap
- I've tried splitting the string
- Some other things not coming to mind
Obviousely I'm getting this wrong and would really appreciate if anybody could point me toward the right direction, to keep in mind user has the ability to load the whole log file if she/he choses to do so but result does not change so it is not my mangling the string introducing the issue.
Thanks in advance for any help!
TextBox/RichTextBox new lines for imported text file
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- PsCustomObject
- Posts: 137
- Last visit: Mon Mar 18, 2024 3:11 am
Re: TextBox/RichTextBox new lines for imported text file
$textbox1.Lines = Get-Content file.log
This maintains the line breaks.
When creating a file in PowerShell use Out-File -append and don't add line breaks. Out-File adds them automatically and correctly.
This maintains the line breaks.
When creating a file in PowerShell use Out-File -append and don't add line breaks. Out-File adds them automatically and correctly.
- PsCustomObject
- Posts: 137
- Last visit: Mon Mar 18, 2024 3:11 am
Re: TextBox/RichTextBox new lines for imported text file
Thanks but all of this is already in place and the source of my headache
Line breaks in this specific context are a necessity as I'm storing log's entries in a variable and then sending that to the log file at the end of a chain of scripts, reason for this appraoch is everything is implemented through Orchestrator and need to fork/switch path according to script's output so having log in a variable is easy to pass down the databus.
Line breaks in this specific context are a necessity as I'm storing log's entries in a variable and then sending that to the log file at the end of a chain of scripts, reason for this appraoch is everything is implemented through Orchestrator and need to fork/switch path according to script's output so having log in a variable is easy to pass down the databus.
Re: TextBox/RichTextBox new lines for imported text file
If there are line breaks in the file then the variable will be an array.
$variable = Get-Content file.log
$textbox1.Lines = $variable
There is no other way to do this. If you assign to Text the text will get clobbered.
$variable = Get-Content file.log
$textbox1.Lines = $variable
There is no other way to do this. If you assign to Text the text will get clobbered.
- PsCustomObject
- Posts: 137
- Last visit: Mon Mar 18, 2024 3:11 am
Re: TextBox/RichTextBox new lines for imported text file
Thanks a lot, I will give this a try and see... worst case I will reowrk a bit the log functionality or simply call an external tool for parsing the file as anyhow this is for internal use by 1st level support.
As usual appreciate your time helping out.
As usual appreciate your time helping out.
Re: TextBox/RichTextBox new lines for imported text file
Mostly there is not enough information to know what it is that you are having an issue with. If you are parsing the file incorrectly then you will lose all lines or cause the output to be scrambled.
A multiline textbox is an array of lines. If you feed it text only it will not be an array but will be a large block of text. It does not work exactly like a RichTextBox.
A multiline textbox is an array of lines. If you feed it text only it will not be an array but will be a large block of text. It does not work exactly like a RichTextBox.
Re: TextBox/RichTextBox new lines for imported text file
Here is a good example of how a textbox works and how it can screw up lines.
- Attachments
-
- Test-TxtLength.psf
- (27.07 KiB) Downloaded 296 times
Re: TextBox/RichTextBox new lines for imported text file
Here is an alternate way to keep from losing the lines:
- Attachments
-
- Test-TextLoad.psf
- (30.1 KiB) Downloaded 327 times