-
Notifications
You must be signed in to change notification settings - Fork 1
ConvertTo DiffString
Converts a specified portion of a string to a diff string with ANSI color codes.
ConvertTo-DiffString -IndexObject <PSObject> -InputString <String> [-Ansi <String>] [-AnsiReset <String>]
[<CommonParameters>]
ConvertTo-DiffString -InputString <String> [-Ansi <String>] [-AnsiReset <String>]
[<CommonParameters>]
ConvertTo-DiffString -InputString <String> -StartIndex <UInt32> [-EndIndex <UInt32>] [-Ansi <String>]
[-AnsiReset <String>] [<CommonParameters>]
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.
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.
@{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.
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
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
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
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
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
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
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
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.