Share via

Data missing

Arunabha Goswami 0 Reputation points
2023-08-23T10:17:20.3066667+00:00
$t = "Server - shutdown in 2014, 2018 "Systems" database The server is expected to be kept until July 30th, 2023, and"
$i=0
if($t -Match ','){
            $Annotations = $t.replace('"',' ').Split(',')
            for($i; $i -le $Annotations.Count;$i++){
                $Annotation+= $Annotations[$i]                
            }
            Write-Output $Annotation
            Write-Output "clear"
        }
For the above sentence I am not getting the full string. I am getting the value upto July 30th, rest is missing. I tried using comma separation and everything but no solution.
Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

2 answers

Sort by: Most helpful
  1. Rich Matheisen 48,116 Reputation points
    2023-08-23T15:26:18.71+00:00

    First, the quoting in the string is incorrect. Replace the 1st and last double-quote with a single-quote.

    Can you explain (or show) what you expect to see as a result of running that code?

    You can do without the need for an intermediate array:

    $t = 'Server - shutdown in 2014, 2018 "Systems" database The server is expected to be kept until July 30th, 2023, and'
    if ($t -Match ','){
           $annotation = $t.replace('"',' ').Replace(',','')
           Write-Output $Annotation
           Write-Output "clear"
    }
    

    The result of running your code (or the code above) is:

    Server - shutdown in 2014 2018  Systems  database The server is expected to be kept until July 30th 2023 and
    clear
    

    Was this answer helpful?


  2. Amira Bedhiafi 42,941 Reputation points MVP Volunteer Moderator
    2023-08-23T10:57:55.3033333+00:00

    You are splitting the string $t on commas, which means that it will break at every comma in the text. The text itself has several commas within it that are not meant to be used as delimiters, which is why you're not getting the expected result.

    If you want to replace double quotes with spaces and print the resulting string, you don't need to split the string at all. You can just do:

    $t = "Barbados Sun Systems Financial Server - shutdown in 2014 Delete after December 1, 2018 ENV: Retired but keep POC: Stephen Galbraith SQL 2000 installed with \"Sun Systems\" database The server is expected to be kept until July 30th, 2023, and we will again follow up with the technical owners to get confirmation to proceed with decommissioning."
    
    $Annotation = $t.Replace('"', ' ')
    
    Write-Output $Annotation
    
    Write-Output "clear"
    
    

    If you were trying to split the string into parts for some other purpose, you'll need to choose a different delimiter or use a more complex method to parse the string, such as a regular expression that takes into account the structure of the data you're working with.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.