Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Split using multiple characters as single delimiter

$
0
0

I would like to use a multi-character string as a single delimiter in the .Split() method.

As shown in the sample below, I would like 'abc' to act as the delimiter, with the result being two elements.

'The cat had ' and '/ tacos at lunch'

I amm missing something in the way PowerShell interprets the 'abc' value.  It appears it is splitting on the individual characters AND whitespace.  I'm not a regex guy.  Splitting on a single character, /, works as expected.

CLS
Get-Date

$strSplitOn   = 'abc'
#$strSplitOn  = '/'
$strSplitText = 'The cat had abc/ tacos at lunch'

$arrTemp      = $strSplitText.Split( $strSplitOn )

Write-Host '  Elements: ' $arrTemp.Length

ForEach( $strItem IN $arrTemp )
{	Write-Host $strItem }

"`r`nDone..."


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>