함수 ucfirst()

Jmnote (토론 | 기여)님의 2018년 10월 21일 (일) 16:39 판 (→‎Perl)

1 개요

함수 ucfirst()
  • "uppercase first"
  • 첫글자를 대문자로 바꾸는 함수

2 Java

public class MyClass {
    static String ucfirst(String str) {
        return  str.substring(0, 1).toUpperCase() + str.substring(1);
    }
    public static void main(String args[]) {
        System.out.println( ucfirst("hello world!") ); // Hello world!
        System.out.println( ucfirst("HELLO WORLD!") ); // HELLO WORLD!
    }
}

3 JavaScript

function ucfirst(s) { return s.charAt(0).toUpperCase()+s.slice(1); }
console.log( ucfirst('hello world!') );
// Hello world!
console.log( ucfirst('HELLO WORLD!') );
// HELLO WORLD!

4 Perl

print ucfirst('hello world!');
# Hello world!
print ucfirst('HELLO WORLD!');
# HELLO WORLD!

5 PHP

<?php
echo ucfirst( 'hello world!' );
# Hello world!
echo ucfirst( 'HELLO WORLD!' );
# HELLO WORLD!

6 Python

s = 'hello world!'
print ( s[0].upper() + s[1:] )
# Hello world!
s = 'HELLO WORLD!'
print ( s[0].upper() + s[1:] )
# HELLO WORLD!

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}