How can I change this script to make all the names in All CAPS?

This topic contains 2 replies, has 3 voices, and was last updated by  Aleksandras Artemjevas 4 months, 3 weeks ago.

  • Author
    Posts
  • #71669

    Vester Martin
    Participant

    $names = 'john smith', 'ludwig van beethoven', 'george washington', 'james van der kampf'

    foreach ($name in $names) {
    $firstName = (Get-Culture).TextInfo.ToTitleCase($name.split()[0])

    $lastName = "
    for ($i = 1; $i -lt $name.split().count; $i++) {
    if ($i -eq $name.split().count – 1) {
    $lastName += (Get-Culture).TextInfo.ToTitleCase($name.split()[$i])
    } else {
    $lastName += $name.split()[$i] + ' '
    }
    }

    Write-Output "$firstName $lastName"
    }

  • #71672

    David Johnson
    Participant

    add a line
    for($name in $names){
    $name=name.toupper()

  • #71689

    Hi, give this a shot

    $names = 'john smith', 'ludwig van beethoven', 'george washington', 'james van der kampf'
    $names.ForEach({
        [string]$fistname, [string]$lastname = $PSItem.split()
        Write-Output "$($fistname.ToUpper()) $((Get-Culture).TextInfo.ToTitleCase($lastname))"
    })
    

You must be logged in to reply to this topic.