How to split a string by comma ignoring comma in double quotes

后端 未结 1 607
北恋
北恋 2020-12-11 05:17

This question has been asked before but I have been trying to work a solution in powershell but am not getting the desired results.

$line =          


        
相关标签:
1条回答
  • 2020-12-11 05:59

    [string].split() method doesn't accept regex on split but just [char[]] or [string[]].

    You can try like this:

     $line -split ',(?=(?:[^"]|"[^"]*")*$)' 
    

    powershell -split accept regex for splitting text

    Using .net you can do it like this:

    [regex]::Split( $line , ',(?=(?:[^"]|"[^"]*")*$)' )
    
    0 讨论(0)
提交回复
热议问题