I'm looking to parse out a specific blob of text to a different file. However, I'm having an issue with the .IndexOf() method when trying to define my endIndex.
The string I'm looking for will start with the phrase:
/* original invocation */
It will then list the original invocation contained in the same type of comment:
/*
~~~
/"
I just finished "Learn PowerShell in a Month of Lunches" so I'm still fresh. But, my thought process is this:
- Get the starting line number of "/* original invocation */" and use that as a startIndex
- Get where-ever the last "*/" is after that and make that line the endIndex.
- Use those values to parse the blob of text I'm after to a file. I assume I could use something like SubString() and pipe it to Out-File.
Here is my script so far:
$file = Get-Content ("file/to/be/read")
$searchString = "/* original invocation */"
$startIndex = $file.IndexOf($searchString)
# Lets say the value of $startIndex is 18676
$endIndex = $file.IndexOf('\*/',$startIndex)
# The error. int IndexOf(string value, int startIndex)
# MethodException: Cannot find an overload for "IndexOf" and the argument count: "2".
I'm pretty lost. If this is easier in Python, please let me know.
The issue I have is when trying to define the endIndex. I get the following error:
MethodException: Cannot find an overload for "IndexOf" and the argument count: "2".
I looked at the overloads for IndexOf and I seem to be matching it, so I must really be missing something. It doesn't seem to matter how many arguments I put in. I also noticed if I just do a random string, I get results of "-1".