Skip to content

Split StringAtIndex

viscalyxbot edited this page Aug 13, 2024 · 1 revision

Split-StringAtIndex

SYNOPSIS

Splits a string at a specified index or range of indices.

SYNTAX

PipelineInput

Split-StringAtIndex -IndexObject <PSObject> -InputString <String> 
 [<CommonParameters>]

StartEndInput

Split-StringAtIndex -InputString <String> -StartIndex <UInt32> -EndIndex <UInt32>
 [<CommonParameters>]

DESCRIPTION

The Split-StringAtIndex function splits a given string at a specified index or range of indices. It can be used to extract substrings from a larger string based on the provided indices.

EXAMPLES

EXAMPLE 1

Split-StringAtIndex -InputString "Hello, World!" -StartIndex 0 -EndIndex 4

This example splits the input string "Hello, World!" at the index specified by StartIndex and then at the index specified by EndIndex and returns the resulting array of substrings.

EXAMPLE 2

@(@{Start = 0; End = 2}, @{Start = 7; End = 11 }) | Split-StringAtIndex -InputString "Hello, world!"

This example splits the input string "Hello, World!" at the indices provided by the pipeline. It will split the string at each StartIndex and EndIndex and returns the resulting array of substrings.

EXAMPLE 3

@(0, 1, 2, 7, 8, 9, 10, 11) | Get-NumericalSequence | Split-StringAtIndex -InputString "Hello, world!"

This example splits the input string "Hello, World!" at the indices provided by the pipeline. It will split the string at each StartIndex and EndIndex and returns the resulting array of substrings.

PARAMETERS

-EndIndex

Specifies the ending index of the substring to be extracted. The value must be less than the length of the input string.

Type: UInt32
Parameter Sets: StartEndInput
Aliases:

Required: True
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-IndexObject

Specifies the index object to split the string. This parameter is used when providing input via the pipeline.

Type: PSObject
Parameter Sets: PipelineInput
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-InputString

Specifies the input string to be split.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-StartIndex

Specifies the starting index of the substring to be extracted. The value must be less than the length of the input string.

Type: UInt32
Parameter Sets: StartEndInput
Aliases:

Required: True
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.String[]

An array of substrings extracted from the input string.

NOTES

The Split-StringAtIndex function is designed to split strings based on indices and can be used in various scenarios where string manipulation is required. To get the indices the function Get-NumericalSequence can be used.

RELATED LINKS

Clone this wiki locally