将大写字母更改为小写字母

Contents [hide]

输出结果

abc


程式码


C

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <ctype.h>
 
int main () {
   int i = 0;
   char str[] = "ABC";
   while( str[i] ) {
      str[i] = tolower(str[i]);
      i++;
   }
   printf("%s\n", str);
   return(0);
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
 
int main (int argc, char *argv[]) {
    std::string s("ABC");
 
    transform (s.begin (), s.end (), s.begin (), tolower);
    std::cout << s << std::endl;
 
    ::exit (EXIT_SUCCESS);
}

Java

1
2
3
4
5
6
public class Lower {
    public static void main(String[] args) {
        String str = "ABC";
        System.out.println( str.toLowerCase() );
    }
}

JavaScript

1
2
let str = "ABC";
console.log(str.toLowerCase());

PHP

1
2
3
<?php
$str = "ABC";
print(strtolower($str)."\n");

Perl

1
2
my $str = "ABC";
print(lc($str)."\n");

Python

1
2
str = "ABC"
print(str.lower())

Ruby

1
2
str = "ABC"
print(str.downcase() + "\n")