Powershell version 7.1,VSCode v5.1x, Net5, Windows 10
Objective: To learn the string.split.overloaddefinitions method and parameters. Using VSCode it is an option from the split to select the overloaddefinitions as...$Hash=$String.split.OverloadDefinitions(?) MS Docs (link included) state that it has 3 options (0,1,2)but the detail is very sparse. Is it 1 numeric or "1" string or literal "RemoveEmptyEntries"? I have tried many variants and none work. So I am seeking some guidance as to what I am missing or misunderstanding. The runtime error when using this overload is always "does not contain a method named 'OverloadDefinitions'." which seems to be an erroneous message. Using Set-Transcript captures the result but this is not useful because the bottom line is still the same error. The C# examples have been tried with worse results. So now what?
The code snippet for testing is... #Start-Transcript "C:\Users\AlPerkins\Desktop\Transcript.txt" #transcript available but not included
https://learn.microsoft.com/en-us/dotnet/api/system.stringsplitoptions?view=net-5.0
$String="Harry & Joanne Joint open statement as of June 4 2021"
$Hash=$String.Split() # OK but with empty entries from spaces. Empties need to be removed.
$Hash=$String.split.OverloadDefinitions("1") # OK in VSCode editor but runtime errors-> 'does not contain a method named 'OverloadDefinitions'. '
$Hash=$String.split.OverloadDefinitions("2") # Ditto
$Hash=$String.split.OverloadDefinitions(1) # Ditto
$Hash=$String.split.OverloadDefinitions(2) # Ditto
$Hash=$String.split.OverloadDefinitions("RemoveEmptyEntries") # Ditto
$Hash=$String.split.OverloadDefinitions("TrimEntries") # Ditto
How to split string by string in Powershell and other
ideas from stackoverflow but my attempts fail - Nothing from here will even compile. The examples here are C# code and I am not a C# guy.
so the above are my best options if I can get the method options to work.
<# $Hash=$String.Split(" ",System.StringSplitOptions "RemoveEmptyEntries" ) #Note the char '-' in these lines ere not type by me but are char('AD')
$Hash=$String.Split(' ',[System.StringSplitOptions]::"TrimEntries")
$Hash=$String.split(' ',[System.StringSplitOptions]::"RemoveEmptyEntries")
$Hash=$String.Split(' ',[System.StringSplitOptions]::"RemoveEmptyEntries, [System.StringSplitOptions]::"TrimEntries")
#>
Anyone that has been successful with this approach please kick start me on the right track because I have fallen of my bike here.
Many Thanks