Hello,
Running the following command, I’m seeing double whitespaces that I need to have removed:
"Heartbeat.vbs : Value" -replace '(Heartbeat.vbs)','' -replace '(:)',''.Trim()
From everything I’ve read, the “.Trim()” should remove all leading and trailing whitespaces: https://msdn.microsoft.com/en-us/library/System.String_methods(v=vs.110).aspx
The end result, I want to just see the word “Value”. Referred to other questions in this subreddit, and various forums, but I can’t seem to get this to work.
Now if I were to take the output from the command above, and perform the following, it works:
$InitialTrim = "Heartbeat.vbs : Value" -replace '(Heartbeat.vbs)','' -replace '(:)',''.Trim() Write-Host $InitialTrim.trim()
The problem, is that I need to keep this as a stored variable within a script. I don’t want it to write to the prompt. I ultimately need the following script variable created:
$TrimVariable = "Value"
Any suggestions on how to accomplish this?
Thanks!
submitted by /u/Day_Dreamer
[link] [comments]
The post Having issues with Trim() for Double whitespaces. appeared first on How to Code .NET.