Как разделить строку в power shell

wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test One" && python one.py
wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test Two" && python two.py
wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test Three" && python three.py
:: -- Switch back to the first pane, so we get a nice 4 squared window.
wt /w 0 fp /t 0
wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test Four" && python four.py
  • For more info and to get a list of all options, including switching between panes and windows and stuff: wt /?

If it doesn’t work correctly, you can put the command on one line too, e.g. creating a new tab to run ping within, returning focus back to the first tab while ping runs:

# cmd: wt /w 0 sp paping 8.8.8.8 -p 443 && wt /w 0 fp /t 0
# powershell: wt /w 0 sp paping 8.8.8.8 -p 443;wt /w 0 fp /t 0
function RunSplit { param ( [string]$program ) $command = "wt /w 0 sp $program;wt /w 0 fp /t 0" Invoke-Expression $command
}

I can now type RunSplit "ping google.com" to ping google in a separate tab.

enter image description here

Do you want to split strings into arrays in PowerShell? In this PowerShell tutorial, I will show you different methods to split strings in PowerShell.

In PowerShell, to split a string into an array, use the -split operator with the string variable. For example, $array = $string -split 'delimiter' splits $string at each occurrence of ‘delimiter’, creating an array $array of the resulting substrings. This method is efficient for parsing strings based on specific separators.

Using the -split Operator

The simplest way to split a string in PowerShell is by using the -split operator. This operator allows you to specify a delimiter, which PowerShell will then use to divide the string into an array of substrings.

$stringToSplit = "one,two,three,four"
$array = $stringToSplit -split ","

In this example, the string “one,two,three,four” is split at each comma, creating an array with four elements: “one”, “two”, “three”, and “four”.

Using the .Split() Method

Another way to split a string is to use the .Split() method in PowerShell. This method is a part of the string object in PowerShell and can take a character or an array of characters as its argument.

$stringToSplit = "one two three four"
$delimiter = " "
$array = $stringToSplit.Split($delimiter)

Here, the .Split() method is used to split the string at each space, resulting in an array of words. You can see the screenshot for the output after executing the script using PowerShell ISE.

Split Strings into Arrays in PowerShell

Split Strings into Arrays in PowerShell with Multiple Delimiters

Example using -split operator

Sometimes, you might need to split a string using multiple delimiters in PowerShell. Both the -split operator and the .Split() method can handle this scenario.

$stringToSplit = "one,two;three:four"
$delimiters = ',|;|:'
$array = $stringToSplit -split $delimiters

In this example, the -split operator uses a regular expression pattern that includes multiple delimiters (comma, semicolon, and colon).

Example using .Split() Method

Here is another example of using .split() method to split strings into arrays in PowerShell with multiple delimiters.

$stringToSplit = "one,two;three:four"
$delimiters = @(',', ';', ':')
$array = $stringToSplit.Split($delimiters)

For the .Split() method, you pass an array of characters as delimiters, and the method splits the string at each instance of any of the characters.

Split Strings into Arrays in PowerShell Preserving Empty Entries

Example using -split operator

By default, both -split and .Split() will omit empty substrings from the resulting array in PowerShell. If you want to include these empty substrings, you need to use an additional option.

$stringToSplit = "one,,two,,three,,four"
$array = $stringToSplit -split ",", 0, "SimpleMatch"

The “SimpleMatch” option tells PowerShell to include empty substrings in the array.

Example using .Split() Method

Here is an example of splitting strings into arrays in PowerShell, preserving empty entries.

$stringToSplit = "one,,two,,three,,four"
$delimiter = ","
$array = $stringToSplit.Split($delimiter, [System.StringSplitOptions]::None)

Here, we use the StringSplitOptions.None enumeration value to include empty substrings in the array.

Conclusion

Splitting strings into arrays is a common and straightforward task in PowerShell. Whether you prefer the -split operator for its simplicity and power with regular expressions, or the .Split() method for its direct approach, both are effective tools in your scripting toolbox.

In this PowerShell tutorial, I have explained how to split strings into arrays in PowerShell using various methods.

You may also like:

PowerShell Split string

One of the most common tasks in PowerShell is manipulating strings. String manipulation involves various operations, such as splitting, joining, and parsing strings. I will walk you through splitting strings into arrays using PowerShell in this guide. We will cover the basics of splitting strings by delimiter, splitting strings by word, and more. By the end of this guide, you will have a solid understanding of how to split strings into arrays in PowerShell.

The Basics of Splitting Strings in PowerShell

split string powershell

PowerShell is a command-line shell and scripting language built on top of the .NET Framework, which means that it has access to all the .NET classes and libraries. Splitting strings is a common task in PowerShell. A string is a sequence of characters, and splitting a string means dividing it into smaller parts. Splitting strings is useful when you want to extract information from a larger string or when you would like to manipulate the string in some way.

The simplest way to split a string into an array in PowerShell is by using the Split() method. This method splits a string into an array of substrings based on a specified delimiter and returns the array. The string split can be achieved with the below syntax:

string.Split(Delimiter [,MaxSubstrings] [,Options])
String -Split Delimiter [,MaxSubstrings] [,Options]
String -Split {scriptblock} [,MaxSubstrings]
-Split String
  • The default delimiter is whitespace, newline, and tab characters. By default, the delimiter character is omitted in the result.
  • Specify the number of substrings to be produced with the ‘Max-SubStrings’ parameter.
  • Use Script Blocks to define delimiter rules.
  • Options such as SimpleMatch and RegexMatch set the scope for splitting strings.
  • Additional parameters include IgnorCase, CultureInvariant, IgnorePatternWhitespace, ExplicitCapture, Singleline and Multiline.

PowerShell Split String Examples

$string = "Hello World!"
$string.Split()

This splits the input string into an array of substrings using a specified delimiter. In this example, we split the string “Hello World!” using the default delimiter whitespace. The Split function returns an array of strings. Output:

We can split a given string into an array of substrings based on a specified delimiter. Here’s an example:

$string= "apple,banana,orange"
$delimiter = ","
$array = $string.Split($delimiter)
$array

In this example, we split the string variable based on the comma delimiter. The resulting array contains three elements: “apple”, “banana”, and “orange”.

split string delimiter

You can access the individual elements of the array using the index number. For example:

$array[0] # will return "apple"
$array[1] # will return "banana"
$array[2] # will return "orange"

Using the PowerShell -split operator

Another way to split strings into an array in PowerShell is by using the PowerShell split operator. The split operator, denoted by the -split keyword, takes a string and a delimiter as input and returns an array of substrings. This operator splits a string into an array of substrings based on a specified delimiter and returns the array. Here’s an example:

$string = "Vanilla-Chocolate-Strawberry-Pistachio"
$delimiter = "-"
$array = $string -split $delimiter
$array

In this example, we use the -split operator to split the string based on the white space delimiter. The resulting array is the same as the previous example.

:/>  Установить виндовс 7 бесплатно через интернет без диска на пк

Splitting Strings by Delimiter in PowerShell

Splitting strings by delimiter is one of the most common ways to split strings in PowerShell. A delimiter is a character or characters that separate the parts of a string. For example, in the string “Alice;Developer;Seattle”, the semicolon is the delimiter.

To split a string by delimiter in PowerShell, you can use the Split method. Here is an example:

$string = "Alice;Developer;Seattle"
$delimiter = ";"
$splitString = $string.Split($delimiter)

In this example, we are splitting the string “Alice;Developer;Seattle” using the , delimiter. The Split method returns an array of strings, which we store in the $splitString variable. You can also use multiple delimiters:

$string = "PowerShell,is;awesome"
$delimiter = "[,;]"
$string.Split($delimiter)
split string examples

Split and Remove Empty Elements

Splitting strings in PowerShell sometimes results in empty array elements, especially when there are multiple consecutive delimiters. For instance, if you’re splitting a CSV string and there are two commas in a row (e.g., “Alice,,Bob”), the result will include an empty element. Here’s a PowerShell example that demonstrates how to split a string and remove any empty elements:

$string = "Alice,,Bob,Charlie,,,Dave"
$delimiter = ","
$array = $string.Split($delimiter, [System.StringSplitOptions]::RemoveEmptyEntries)
$array
split strign remove duplicates

Alternatively, you can use the “Where” clause to remove empty elements. Here is how:

# Sample string with double commas
$data = "Alice,,Bob,Charlie,,,Dave"
# Split the string by comma and filter out empty elements
$names = $data -split "," | Where-Object { $_ -ne "" }
# Display the results
$names

Splitting Strings into Variables

Sometimes, you might want to split a string into variables directly:

$data = "John,Doe,30"
$name, $surname, $age = $data -split ","
$name #Output: John
$SurName #Output: Doe
$Age #Output: 30

This approach assigns each part of the split string to a separate variable, streamlining your data processing tasks.

Splitting Strings Word by Word in PowerShell

Splitting strings by word is another common way to split strings in PowerShell. When you split a string by word, you are dividing the string into smaller parts based on the spaces between the words.

To split a string by word in PowerShell, you can use the Split method without specifying a delimiter. Here is an example:

$string = "PowerShell scripting tutorials beginner guides"
$SplitString = $string.Split()
$SplitString

In this example, we are splitting the string “PowerShell scripting tutorials beginner guides” by word. Since we did not specify a delimiter, the Split method uses the spaces between the words as the delimiter. The Split method returns an array of strings, which we store in the $splitString variable.

PowerShell
scripting
tutorials
beginner
guides
# Sample user feedback
$feedback = "I love the new update on settings! However, I did notice a minor glitch with the settings page due to this update. Please look into it."
# Splitting the feedback word by word
$words = $feedback -split "\W+" # \W+ regex pattern splits by non-word characters
# Count specific keywords
$updateCount = ($words | Where-Object { $_ -eq "update" }).Count
$settingsCount = ($words | Where-Object { $_ -eq "settings" }).Count
# Display the results
Write-Output "Update Count: $updateCount"
Write-Output "Settings Count: $settingsCount"

When you run the script, it will display the count of the specified keywords, allowing you to gauge the frequency of certain topics in the feedback.

Splitting Strings into Arrays in PowerShell

Splitting strings into arrays in PowerShell is a useful technique for working with strings. When you split a string into an array, you can manipulate the individual parts of the string separately.

To split a string into an array in PowerShell, you can use the Split method. Here is an example:

$string = "John,Doe,30"
$delimiter = ","
$splitString = $string.Split($delimiter)

In this example, we are splitting the string “John,Doe,30” into an array using the , delimiter. The Split method returns an array of strings, which we store in the $splitString variable.

Using ForEach to Split Strings into Arrays in PowerShell

The ForEach loop is a powerful construct in PowerShell that allows you to iterate over an array and perform an action on each element. You can use the ForEach loop to split a string into an array and then manipulate the individual parts of the string separately.

Here is an example:

$string = "John,Doe,30"
$delimiter = ","
$splitString = $string.Split($delimiter)
ForEach ($part in $splitString) { Write-Output $part
}

In this example, we are first splitting the string “John,Doe,30” into an array using the , delimiter. We then use the ForEach loop to iterate over each element in the array and output it to the console.

Parse and Extract Values from CSV Files in PowerShell

Name,Age,Email
John,30,john@example.com
Jane,25,jane@example.com

To split each row into an array of fields, you can split each line by the comma character:

$csvLines = Get-Content -Path "C:\data\file.csv"
$data = foreach ($line in $csvLines) { $line -split ","
}

In this example, the Get-Content cmdlet is used to read the CSV file and store each line in the $csvLines variable. The foreach loop then iterates over each line, splits it by the comma character, and stores the resulting array of fields in the $data array.

Splitting strings into arrays using regular expressions in PowerShell

$myString = "apple banana cherry"
$myArray = $myString -split "\s+"

In this example, the string “apple banana cherry” is split into three substrings: “apple”, “banana”, and “cherry”. The resulting array, $myArray, contains these three substrings. Regular expressions can be used to split strings based on any custom pattern or condition. Here, the “\s+” denotes one or more whitespace characters. Let’s consider another example: You have a string with mixed product names and quantities. You want to get the product names from the string:

$shipmentData = "Laptop45Charger32Mouse12Keyboard5"
$products = $shipmentData -split '\d+'
$products
Laptop
Charger
Mouse
Keyboard

This flexibility makes regular expressions a powerful tool for parsing strings into arrays in PowerShell.

Splitting strings with multiple characters or by a word

$Recipe = "Flour 200g AND Sugar 150g AND Eggs 3 AND Vanilla Extract 1 tsp"
$ingredients = $Recipe -split "AND"
Foreach ($ingredient in $ingredients) { Write-Output $ingredient.Trim()
}
Flour 200g
Sugar 150g
Eggs 3
Vanilla Extract 1 tsp

Here is another example:

$productInfo = "ProductName: Laptop DETAIL Price: AED-1000 DETAIL Warranty: 2 years DETAIL"
$details = $productInfo -split "DETAIL"
foreach ($detail in $details) { Write-Output $detail.Trim()
}
ProductName: Laptop
Price: AED-2000
Warranty: 2 years

Split a String by a new line Character

$myString = "Line 1`r`nLine 2`r`nLine 3"
$myArray = $myString -split "\r\n"

In this example, the string with new line characters is split into three substrings: “Line 1”, “Line 2”, and “Line 3”. The resulting array, $myArray, contains these three substrings. Here is another example:

# Multiline string example
$multilineText = @"
This is line 1
This is line 2
This is line 3
This is line 4
"@
# Split the multiline string into individual lines
$Lines = $multilineText -split "`r`n"
$i=1
# Process each line (for demonstration, we'll just print each line with a prefix)
ForEach ($Line in $Lines) { Write-host "Processed Line# $i : " +$Line $i++
}

You can also read from a text file and split line by line:

$LogData = Get-Content "C:\Temp\AppLog.txt"
$Entries = $LogData -split "`n"

Similarly, you can split a string based on any escape character, like a tab.

$string = "Value1`tValue2`tValue3"
$splitArray = $string.Split("`t")
$splitArray

The split-path cmdlet in PowerShell

$Path= "C:\Program Files\Microsoft"
$myArray = $Path -Split "\\"

In this example, the string “C:\Program Files\Microsoft” is split into four substrings: “C:”, “Program Files”, and “Microsoft”. The resulting array, $myArray, contains these four substrings. What if you want to get the File or folder name or the parent folder in a path? Well, here is where the Split-Path can be helpful.

:/>  Подключаем файловую систему WSL2 в Windows 10 как диск · АлтунинВВ.Блог

Split-Path is a handy cmdlet in PowerShell that provides the functionality to separate the leaf (often the filename or the last folder name) from its parent path. It’s especially useful when working with file or directory paths.

$LogFilePath = "C:\Temp\Logs\AppLog.txt"
#Get Parent Folder - C:\Temp\Logs
$Directory = Split-Path -Path $LogFilePath -Parent
Write-Output $Directory
#Get File Name - AppLog.txt
$Filename = Split-Path -Path $LogFilePath -Leaf
Write-Output $Filename

The Split-Path cmdlet is particularly useful when working with file paths or directory paths in PowerShell.

Advanced Techniques in PowerShell Split String

In addition to the above methods, other advanced techniques can be used to split strings into arrays. For instance, you can include the delimiter in the result, split the string characters into an array, limit the number of substrings, do a case-sensitive split, and use the Regular Expression (RegEx) matching to split strings by more complex patterns.

Include Delimiter in Result

By default, The Split method will remove the delimiter characters from the resulting array. If you want to preserve the delimiter characters in the resulting array, you can wrap the delimiters in parentheses. For example:

$string = "apple;banana,orange"
$array = $string -split "(;|,)"

This will create an array with five elements: "apple", ";", "banana", ",", and "orange".

Split a String into a Character Array

To Split a string into individual characters, use:

$string = "AEIOU"
$characters = $string.ToCharArray()
$characters

Limit the number of resulting substrings

You can use the “-Maxsubstrings” parameter to limit the maximum number of substrings when you split a string. Here’s how it works:

$String = "one,two,three,four,five"
$string -split ",", 3
#Result:
#one
#two
#three,four,five
  • The string is split at the first two comma occurrences because we’ve set the MaxSubstrings parameter to 3.
  • The third substring (the last one) will contain the rest of the string after the first two splits, even if it includes more delimiters.

This is particularly useful when you’re only interested in processing the first few fields in a delimited string or when you want to handle the remainder of a string as a single entity after a certain number of splits.

Using SimpleMatch and IgnoreCase Parameters

SimpleMatch parameter instructs PowerShell to look for a dot (.) and not for any character. The IgnoreCase – Tells the operator to split regardless of the character case.

$FQDN = "fileserver.corp.crescent.com"
$Parts = $FQDN -split ".",0,"SimpleMatch","IgnoreCase"
$Parts

Case-sensitive split

Suppose you have a string where you’re using both lowercase and uppercase instances of the word “AND” as delimiters. However, you only want to split the string using the uppercase “AND” while keeping the lowercase “and” intact. Here is how you can use the CSplit operator:

# Sample user feedback
$feedback = "I suggest adding a dark mode AND improving the search function. The mobile app crashes often and needs fixing AND please add a tutorial for new users."
# Splitting the feedback case-sensitively at "AND"
$suggestions = $feedback -csplit "AND"
# Display each suggestion separately
$suggestions | ForEach-Object { Write-Output "Suggestion: $_" }

Wrapping up

In this guide, we covered the basics of splitting strings in PowerShell. We learned how to split strings using the Split() method, the -split operator, split strings by delimiter, split strings by word, and split strings into arrays. We also used ForEach to split strings into arrays and used tips and tricks for efficient string splitting.

Splitting strings is just one of the many features that make PowerShell an efficient and effective tool for manipulating data. These techniques are useful for processing and manipulating data in your PowerShell scripts. By understanding the basics of splitting strings in PowerShell and using regular expressions, you can save time and effort when working with large data sets.

What is the purpose of the Split method in PowerShell?

How do I split a string using a specific delimiter?

To split a string using a specific delimiter, you can use the Split method and provide the delimiter as a parameter. For example:
$text = "apple,banana,cherry"
$fruits = $text.Split(",")

Can I split a string using multiple delimiters?

How can I split a string and remove empty entries?

Can I split a multi-line string into an array of lines?

How can I split a string and store the substrings in separate variables?

To split a string and store the substrings in separate variables, you can use the Split method and assign the resulting array to multiple variables. For example:
$text = "John,Doe,30"
$firstName, $lastName, $age = $text.Split(",")

Can I split a string based on a specific number of characters in PowerShell?

How can I split a string based on a regular expression pattern in PowerShell?

What is the difference between -split Operator and Split() Method in PowerShell?

The -split operator is a PowerShell-specific operator that splits a string based on a specified delimiter. It returns an array of substrings. On the other hand, Split() is a .NET method available on string objects. It also splits a string but provides more advanced options, such as specifying the maximum number of substrings to return or using a regular expression as the delimiter.

Today, I thought I would do a different example of split strings in PowerShell. In this tutorial, I will show you how to split a string by word in PowerShell with a complete script and examples.

Now, let us check various methods to split a string by word in PowerShell.

Method 1: Using the -split Operator with a Specific Word

The -split operator in PowerShell can be used with a specific word as the delimiter.

Here is a complete example:

$string = "United States is a beautiful country"
$delimiter = "beautiful"
$parts = $string -split $delimiter
$parts

In this example, the string "United States is a beautiful country" is split into an array using the word "beautiful" as the delimiter. The output will be:

United States is a country

I executed the above PowerShell script, and you can see the output in the screenshot below:

Split a String by Word in PowerShell

Method 2: Using the .Split() Method with a Specific Word

The .Split() method in .NET can also be used to split a string by a specific word in PowerShell. However, this method requires converting the string into a character array.

Here is an example:

$string = "United States is a beautiful country"
$delimiter = "beautiful"
$parts = $string -split $delimiter
$parts

In this example, the string is split using the word "beautiful" as the delimiter. The output will be:

United States is a country

After executing the code, you can see the output in the screenshot below:

How to Split a String by Word in PowerShell

Read How to Split Strings by Newlines in PowerShell?

:/>  10 способов открыть редактор локальной групповой политики в windows 11

Method 3: Using Regular Expressions with -split

PowerShell’s -split operator can work with regular expressions to split a string by word. This can be useful if the delimiter word appears in different forms (e.g., case-insensitive).

$string = "United States is a beautiful country"
$delimiter = "beautiful"
$parts = $string -split "($delimiter)"
$parts

In this example, the regular expression ($delimiter) is used to split the string by the word "beautiful". The output will be:

United States is a country

Method 4: Using -replace and -split

In PowerShell, you can also use the -replace operator to replace the specific word with a unique character or string, and then use the -split operator.

$string = "United States is a beautiful country"
$delimiter = "beautiful"
$string = $string -replace $delimiter, "|"
$parts = $string -split "\|"
$parts
United States is a country

Read Add Double Quotes in a String in PowerShell

Method 5: Using Select-String and -match

You can also use Select-String and -match to extract parts of the string before and after the specific word in PowerShell.

$string = "United States is a beautiful country"
$delimiter = "beautiful"
if ($string -match "(.*)$delimiter(.*)") { $before = $matches[1] $after = $matches[2]
}
$before
$after

This script uses a regex pattern to capture everything before and after the word "beautiful". The output will be:

United States is a country

You can see the screenshot below:

powershell split string by word

Conclusion

In this PowerShell tutorial, I have explained how to split a string by word in PowerShell using various methods like:

  • Using the -split Operator with a Specific Word
  • Using the .Split() Method with a Specific Word
  • Using Regular Expressions with -split
  • Using -replace and -split
  • Using Select-String and -match

You may also like:

In PowerShell, a pretty common task is to split a string into one or more substrings. Splitting a string is always done based on a delimiter. This can be pretty much anything in the string, like a space, or comma, or a specific character.

To split a string in PowerShell we will use the -split operator or the Split method. This allows you to split a string into an array of substrings based on a specified delimiter, how many substrings you want to return, and some other options.

In this article, we will look at how to simply split a string in Powershell and at some of the advanced options.

The -split operator or Split() method is a built-in way to split a string into an array of substrings. You provide a delimiter (or a regular expression pattern) to determine where the string should be split.

For example, to split a string into each word, we can use the space as a delimiter. This will return each individual word of the string:

$string = "The best PowerShell blog"
$string -split " "
# Result
The
best
PowerShell
blog
powershell split string

In the example above we outputted the results directly to the console, but normally you want to use the results in your script. When you store the results in a variable, you will get an array with each substring.

Taking the example, below, if we only want to get the date from the string, we can split the string, using the space as a delimiter, and only return the last item from the array:

$string = "Delivery-contract-20230401"
$splitArray = $string.Split("-")
# Select the last item from the array
$splitArray[-1]
# Result
20230401

Good to know is that if you don’t specify a delimiter, then it will split on space as well. The split operator is case-insensitive by default, if you need to be case-sensitive, then use the -csplit operator.

In some case you might want to split a string on a comma, or other delimiter, but each substrings starts with a space. To remove the spaces from each substring you can best use the Trim() method:

$string = "apple,banana,cherry,date"
$string.split(',')
# Result
apple banana cherry date
# Remove space by including trim:
$string.split(',').trim()

Using Multiple Delimiters

$string = "apple,banana,cherry|date"
$string -split "[,|]"
# Result
apple
banana
cherry
date

Regular expressions can be used to define custom patterns on which you want to split a string. I won’t go into detail on how regular expressions work, but I will show you a few examples to get you started:

# Split on multiple spaces or tabs:
$string = "This is a string with multiple spaces and tabs"
$string -split "\s+"
# Split on decimals:
$string = "Hello123World456Test789"
$string -split "\d+"
# Split on sentences:
$string = "This is a sentence. And here is another one! Finally, a third sentence."
$splitArray = $string -split "(?<=[.!?])\s+"

Limit the Results

By default, the split method will return all the substrings, but what if you only need the first part? For this, we can use the Maxsubstrings parameter, which will limit the number of substrings that are returned.

You can use a positive number to start counting from the beginning of the string and a negative number to start counting from the end of the string. For example, we only want to separate the date from the file name:

$string = "20230401-La-srv-dc01 Event Log.log"
$string -split "-", 2
# Result
20230401
La-srv-dc01 Event Log.log

The advantage of limiting the results, is that it can speed up your script. With a single string you won’t notice it. But if you are processing thousands of records, then getting only what you need can save a couple of seconds of your script run time.

Wrapping Up

Splitting string in PowerShell is pretty straight forward with the spit method or operator. If you only want to have to first n characters of a string, then you should use the substring method in PowerShell.

I hope you found this article useful, if you have any questions, just drop a comment below.

💡 TIP:
Operator names are case-insensitive.

Operator

str -Split delimiter

Return a Array.

  • delimiter is a string, can be multiple characters.
  • by default, delimiter is case-insensitive.
  • by default, delimiter is interpreted as Regular Expression.
  • The delimiters are removed from string. To include them in string, add parenthesis around it. e.g. "(,)" splits string by comma, but include it in the result array.
 
 
str -Split delimiter, max
  • Split up to max count. Rest of string is concatenated as last element in array.
  • max value of 0 means return all.
  • A negative max gets strings from the right.

when including delimiter in result, the delimiter does not count towards max count.

 = "a b c" , 1 (1 .length) = "a b c" , 2 (2 .length)
str -Split delimiter, max, options
  • combination of
  • SimpleMatch
  • IgnoreCase
  • combination of
  • RegexMatch
  • IgnoreCase
  • CultureInvariant
  • IgnorePatternWhitespace
  • ExplicitCapture
  • Singleline
  • Multiline
 = , 0 , 
 = , 0 , 
str -Split {ScriptBlock}
str -Split {ScriptBlock}, Max
-iSplit

Case-insensitive. Same as -Split.

-cSplit
-Split str

Split string by whitespace such as space, tab, line return char.

Return a Array .

 
-Split (str1, str2, etc)

Split multiple strings.
Return a single array.

 = (, )

PowerShell String