Skip to content

Optimize-String

SYNOPSIS

Optimize a string by removing or replacing specific patterns.

SYNTAX

Optimize-String [-String] <String> [-Remove <String[]>] [-Replace <String[]>] [<CommonParameters>]

DESCRIPTION

This function processes a string (or a collection of strings) and removes or replaces specific patterns based on the provided criteria. It supports removing diacritics, spaces, numbers, special characters, HTML tags, and more. Additionally, it allows replacing patterns such as converting case, replacing dashes, or converting tabs to spaces.

EXAMPLES

EXAMPLE 1

Optimize-String -String "Hello World!" -Remove "SpecialChars"

Removes special characters from the string "Hello World!".

EXAMPLE 2

Optimize-String -String "  Hello   World  " -Remove "LeadingSpaces", "TrailingSpaces", "DoubleSpaces"

Optimizes the string by removing leading, trailing, and double spaces.

EXAMPLE 3

Optimize-String -String "hello world" -Replace "LowerToUpperCase"

Converts the string "hello world" to uppercase.

PARAMETERS

-String

The string (or collection of strings) to be optimized.

Type: String
Parameter Sets: (All)
Aliases:

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

-Remove

Specifies the patterns to remove from the string. Valid values are: - Diacritics: Removes diacritical marks. - AllSpaces: Removes all spaces. - LeadingSpaces: Removes leading spaces. - TrailingSpaces: Removes trailing spaces. - DoubleSpaces: Removes double spaces. - LowerCase: Removes lowercase letters. - UpperCase: Removes uppercase letters. - Numbers: Removes numeric characters. - SpecialChars: Removes special characters. - NewLines: Removes newline characters. - Tabs: Removes tab characters. - HTMLTags: Removes HTML tags.

Type: String[]
Parameter Sets: (All)
Aliases:

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

-Replace

Specifies the patterns to replace in the string. Valid values are: - LowerToUpperCase: Converts lowercase letters to uppercase. - UpperToLowerCase: Converts uppercase letters to lowercase. - DashToHyphen: Replaces dashes with hyphens. - SmartQuotes: Replaces smart quotes with standard quotes. - TabsToSpaces: Converts tabs to spaces.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
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