Skip to content

ConvertTo DiffString

viscalyxbot edited this page Aug 13, 2024 · 1 revision

ConvertTo-DiffString

SYNOPSIS

Converts a specified portion of a string to a diff string with ANSI color codes.

SYNTAX

PipelineInput

ConvertTo-DiffString -IndexObject <PSObject> -InputString <String> [-Ansi <String>] [-AnsiReset <String>]
 [<CommonParameters>]

InputStringOnly

ConvertTo-DiffString -InputString <String> [-Ansi <String>] [-AnsiReset <String>]
 [<CommonParameters>]

StartEndInput

ConvertTo-DiffString -InputString <String> -StartIndex <UInt32> [-EndIndex <UInt32>] [-Ansi <String>]
 [-AnsiReset <String>] [<CommonParameters>]

DESCRIPTION

The ConvertTo-DiffString function converts a specified portion of a string to a diff string with ANSI color codes. It can be used to highlight differences in text or display changes in a visually appealing way.

EXAMPLES

EXAMPLE 1

ConvertTo-DiffString -InputString "Hello, world!" -StartIndex 7 -EndIndex 11

Converts the portion of the input string from index 7 to index 11 to a diff string with the default ANSI color codes.

EXAMPLE 2

@{Start = 7; End = 11 }  | ConvertTo-DiffString -InputString "Hello, world!"

Converts the portion of the input string from index 7 to index 11, provided through pipeline input, to a diff string with the default ANSI color codes.

PARAMETERS

-Ansi

Specifies the ANSI color code to apply to the converted portion. The default value is '30;43m', which represents black text on a yellow background.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 30;43m
Accept pipeline input: False
Accept wildcard characters: False

-AnsiReset

Specifies the ANSI color code to reset the color after the converted portion. The default value is '0m', which resets the color to the default.

Type: String
Parameter Sets: (All)
Aliases:

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

-EndIndex

Specifies the end index of the portion to convert. This parameter is optional when using start and end indices. If not provided, only one character will be converted specified by the start index.

Type: UInt32
Parameter Sets: StartEndInput
Aliases:

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

-IndexObject

Specifies the input object containing the start and end indices of the portion to convert. This parameter is mandatory when using pipeline input.

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 convert. This parameter is mandatory when using start and end indices or when only the input string is provided.

Type: String
Parameter Sets: (All)
Aliases:

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

-StartIndex

Specifies the start index of the portion to convert. This parameter is mandatory when using start and end indices.

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

NOTES

This function uses ANSI escape sequences to apply color codes to the converted portion of the string. The resulting diff string can be displayed in a console or terminal that supports ANSI color codes.

RELATED LINKS