function ConvertTo-PascalCase {
param (
[string]$inputString
)
# Convert the string to lowercase and split it into words
$words = $inputString.ToLower() -split '\s+'
# Capitalize the first letter of each word
for ($i = 0; $i -lt $words.Length; $i++) {
if ($words[$i].Length -gt 0) {
$firstChar = $words[$i].Substring(0,1).ToUpper()
$remainingChars = $words[$i].Substring(1)
$words[$i] = $firstChar + $remainingChars
}
}
# Join the words together without spaces
$pascalCaseString = -join $words
return $pascalCaseString
}
And then do:
$tacticsTags = $null
if ($row.Tactics) {
Split tactics into individual tactics based on comma
$tacticList = $row.Tactics -split ','
$processedTactics = @()
foreach ($tactic in $tacticList) {
$tactic = $tactic.Trim()
# Check if the tactic is already in PascalCase
if ($tactic -match '^[A-Z][a-z]+(?:[A-Z][a-z]+)*$') {
# Already PascalCase, keep as is
$processedTactics += $tactic
} else {
# Convert to PascalCase
$convertedTactic = ConvertTo-PascalCase -inputString $tactic
$processedTactics += $convertedTactic
}
}
# Join the processed tactics back into a comma-separated string
$finalTacticsString = $processedTactics -join ','
# Assign to tacticsTags
$tacticsTags = " `"tactics`" = `"$finalTacticsString`","
Something like:
function ConvertTo-PascalCase { param ( [string]$inputString )
}
And then do: $tacticsTags = $null if ($row.Tactics) {
Split tactics into individual tactics based on comma
}