0

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

1
  • Late to the party here but I finally resolved this for my purpose with the following. # $TextObj=$text.Split("`n", [System.StringSplitOptions]::RemoveEmptyEntries::TrimEntries ). The sequence seems important as swapping removeemptyentries and trimentries returned an error. It also seems that an entry that contains spaces (char(32) ) is NOT empty. Commented Jan 18, 2023 at 15:12

2 Answers 2

0

OK, so far after a VSCode update to 1.57 $Split=$FName.Split(" ", [System.StringSplitOptions]::RemoveEmptyEntries) This now works but it still will not work with... $Split=$Fname.Split.OverLoadDefinitions( ) Seems like this a PS problem as every effort returns an error 'Method OverloadDefinition unknown'.

Sign up to request clarification or add additional context in comments.

Comments

0

Since original post I have no responses except a mysterious prompt to update VSCode v1.56 to VSCode v1.57. As I earlier stated this improved things immensely albiet that the method $Hash=$String.split.OverloadDefinitions() still errored. Since then I have reviewed and checked the string.split further and again mysteriously the method ...split.OverloadDefinitions is no longer an option in IntelliSense. So this was a VSCode bug issue. Issue Closed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.