I am currently parsing strings from .cpp files and need a way to display string blocks of multiple lines using the _T syntax. To exclude one line _T strings, I included a -notmatch “;” parameter to exclude them. This also excludes the last line of the string block, which I need. So I need to display the next string, so that the last string block with “;” is included.
I tried $foreach.moveNext() | out-file C:/T_Strings.txt -append but no luck.
Any help would be greatly appreciated. 🙂
foreach ($line in $allLines)
{
$lineNumber++
if ($line -match "^([0-9\s\._\)\(]+$_=<>%#);" -or $line -like "*#*" -or $line -like "*\\*" -or $line -like "*//*" -or $line -like "*.dll* *.exe*")
{
continue
}
if ($line -notlike "*;*" -and $line -match "_T\(\""" ) # Multiple line strings
{
$line | out-file C:/T_Strings.txt -append
$foreach.moveNext() | out-file C:/T_Strings.txt -append
}
In your sample,
$foreachisn’t a variable, so you can’t call a method on it. If you want an iterator, you’ll need to create one:I would recommend you don’t use regular expressions, though. Parse the C++ files instead. Here’s the simplest thing I could think of to parse out all _T strings. It doesn’t handle:
You’ll have to add those checks yourself. If you only want multi-line _T strings, you’ll have to filter out single line strings, too.