0

現在、.cpp ファイルから文字列を解析しており、_T 構文を使用して複数行の文字列ブロックを表示する方法が必要です。1 行の _T 文字列を除外するために、-notmatch ";" を含めました。それらを除外するパラメーター。これにより、必要な文字列ブロックの最後の行も除外されます。したがって、最後の文字列が「;」でブロックされるように、次の文字列を表示する必要があります。含まれています。

$foreach.moveNext() | を試してみました out-file C:/T_Strings.txt -追加しますが、うまくいきません。

どんな助けでも大歓迎です。:)

    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
    }
4

2 に答える 2

1

サンプルで$foreachは、​​変数ではないため、メソッドを呼び出すことはできません。イテレータが必要な場合は、作成する必要があります。

$iter = $allLines.GetEnumerator()

do
{
    $iter.MoveNext()
    $line = $iter.Current
    if( -not $line )
    {
        break
    }
} while( $line )

ただし、正規表現は使用しないことをお勧めします。代わりに C++ ファイルを解析してください。すべての_T 文字列を解析するために考えられる最も簡単なことを次に示します。処理しません:

  • コメントアウトされた _T 文字列
  • _T 文字列内の ")
  • ファイルの末尾にある _T 文字列。

これらのチェックは自分で追加する必要があります。複数行の _T 文字列のみが必要な場合は、単一行の文字列も除外する必要があります。

$inString = $false
$strings = @()
$currentString = $null

$file = $allLines -join "`n"
$chars = $file.ToCharArray()
for( $idx = 0; $idx < $chars.Length; ++$idx )
{
    $currChar = $chars[$idx]
    $nextChar = $chars[$idx + 1]
    $thirdChar = $chars[$idx + 2]
    $fourthChar = $chars[$idx + 3]

    # See if the current character is the start of a new _T token
    if( -not $inString -and $currChar -eq '_' -and $nextChar -eq 'T' -and $thirdChar -eq '(' -and $fourthChar -eq '"' )
    {
        $idx += 3
        $inString = $true
        continue
    }

    if( $inString )
    {
        if( $currChar -eq '"' -and $nextChar -eq ')' )
        {
            $inString = $false
            if( $currentString )
            {
                $strings += $currentString
            }
            $currentString = $null
        }
        else
        {
            $currentString += $currChar
        }
    }
}
于 2012-06-06T21:12:23.577 に答える
1

これを行うための構文を考え出しました:

$foreach.movenext()
$foreach.current | out-file C:/T_Strings.txt -append

次に移動してから、現在の foreach 値をパイプする必要があります。

于 2012-06-07T21:20:36.140 に答える