Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:14:54+00:00 2026-06-05T12:14:54+00:00

I am currently parsing strings from .cpp files and need a way to display

  • 0

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
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:14:56+00:00Added an answer on June 5, 2026 at 12:14 pm

    In your sample, $foreach isn’t a variable, so you can’t call a method on it. If you want an iterator, you’ll need to create one:

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

    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:

    • commented out _T strings
    • a “) in the _T string
    • a _T string at the end of a file.

    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.

    $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
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently we're parsing arp request output from the command line. string cmd = arp
I'm currently working with parsing some data from SQL Server and I'm in need
Hi I am currently having a problem with parsing an Xml string without any
I am currently trying to pass a generated JSON string to dojo for parsing
I am currently parsing large text files with Python 2.7, some of which were
My map is currently inefficient when parsing one particular set of files (a total
I currently have a csv file that I'm parsing with an example from here:
At work I am parsing large XML files using the DefaultHandler class. Doing that,
I need to parse sections from a string of HTML. For example: <p>Lorem ipsum
I am trying to capture sub-strings from a string that looks similar to 'some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.