strtoupper

strtoupper(string $string): string

Converts all letters in a string to uppercase.

C C23

C23
#include <ctype.h>
#include <stdio.h>
int main(void) {
    const char *s = "hello";
    for (; *s; s++) {
        putchar(toupper((unsigned char)*s)); // uppercase each character
    }
    putchar('\n');
    // toupper is byte-wise: ASCII only, the é bytes pass through unchanged
    const char *acc = "café";
    for (; *acc; acc++) putchar(toupper((unsigned char)*acc));
    putchar('\n');
    return 0;
}
Output
HELLO
CAFé

C++ C++26

C++26
#include <cctype>
#include <iostream>
#include <string>
int main() {
    std::string s = "hello";
    for (char& c : s) c = (char)std::toupper((unsigned char)c);
    std::cout << s << "\n";
    // toupper is byte-wise: ASCII only, é passes through unchanged
    std::string acc2 = "café";
    for (char &c : acc2) c = (char)std::toupper((unsigned char)c);
    std::cout << acc2 << "\n";
    return 0;
}
Output
HELLO
CAFé

C# v11.0.100

v11.0.100
Console.WriteLine("hello".ToUpperInvariant());
// ToUpperInvariant handles Unicode: é becomes É
Console.WriteLine("café".ToUpperInvariant());
Output
HELLO
CAFÉ

Go v1.27.4

v1.27.4
package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println(strings.ToUpper("hello"))

	// ToUpper handles Unicode: é becomes É
	fmt.Println(strings.ToUpper("café"))
}
Output
HELLO
CAFÉ

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        System.out.println("hello".toUpperCase());
        // toUpperCase handles Unicode: é becomes É
        System.out.println("café".toUpperCase());
    }
}
Output
HELLO
CAFÉ

JavaScript v26.13.1

v26.13.1
console.log("hello".toUpperCase())
// toUpperCase handles Unicode: é becomes É
console.log("café".toUpperCase())
Output
HELLO
CAFÉ

PHP v8.6.0

v8.6.0
echo strtoupper("hello"), "\n";
// strtoupper is byte-wise: only ASCII a-z change, é stays lowercase
echo strtoupper("café"), " vs ", mb_strtoupper("café", "UTF-8");
Output
HELLO
CAFé vs CAFÉ

Python v3.15.2

v3.15.2
print("hello".upper())
print("café".upper())  # str.upper handles Unicode: é becomes É
Output
HELLO
CAFÉ

Rust v1.99.1

v1.99.1
fn main() {
    println!("{}", "hello".to_uppercase());

    println!("{}", "café".to_uppercase()); // Unicode-aware: é becomes É
}
Output
HELLO
CAFÉ

TypeScript v26.13.1

v26.13.1
console.log("hello".toUpperCase());
console.log("café".toUpperCase()); // Unicode-aware: é becomes É
Output
HELLO
CAFÉ

Language differences

C: has no built-in containers or higher-order functions; the example converts each character with toupper.

Go: strings.ToUpper.

Java: .toUpperCase().

JavaScript: .toUpperCase().

PHP: naming styles vary — strtoupper.

Python: .upper().

Rust: uses the to_uppercase() method.