Created
April 17, 2013 13:35
-
-
Save ChangJoo-Park/5404338 to your computer and use it in GitHub Desktop.
String Class의 사용법을 알아봅니다.
http://ruby-doc.org/core-1.9.3/String.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
=begin | |
**이 문서는 루비 1.9.3-p392 버전의 Ruby core API 기반의 메소드를 사용합니다.** | |
** 작성자 정보 | |
** 박창주 | |
** pcjpcj2@gmail.com | |
** http://parkcj.wordpress.com | |
** 2013-04-07 | |
조금 더 문자열에 대해서 알아보자. | |
루비는 문자열처리에 강한 언어이다. | |
문자열에 관한 여러가지 기능들을 사용해 보자. | |
이번에 알아볼 기능들 | |
문자열 합치기, 문자열 비교하기, 특정 위치의 문자 보기, 첫글자 대문자 만들기 | |
대문자 <-> 소문자, 문자열 정렬하기, 문자열 자르기, 문자열 길이 구하기, 특정 단어 갯수 구하기, 특정 단어 위치 구하기 | |
특정 문자열 문자 바꾸기, 10진수 -> 8진수, 16진수로 바꾸기등등......... | |
더 많은 내용은 이곳에 있다. | |
http://www.ruby-doc.org/core-2.0/String.html | |
=end | |
puts "하나의 문자를 계속 조작을 당할 poor_string 에 넣고 가지고 놀자" | |
poor_string = "Ji Sung Park is midfielder for English club Queens Park Rangers." | |
puts poor_string | |
puts "문자열 길이 구하기" | |
puts poor_string.length | |
puts poor_string.size | |
puts "문자열 대,소문자 바꾸기" | |
puts poor_string.downcase | |
puts poor_string.upcase | |
puts poor_string.capitalize | |
puts poor_string.swapcase | |
puts "문자열에 특정 문자열 추가하기" | |
puts poor_string.concat "!" | |
puts poor_string.concat "not Manchester United" | |
# chomp와 chop의 차이를 알아보자 | |
puts "문장의 맨 끝에 있는 United 를 지워보자" | |
puts poor_string.chomp "United" | |
puts "맨 마지막 글자를 지워보자" | |
puts poor_string.chop | |
puts "각 글자 사이를 띄어 보자" | |
poor_string.each_char {|c| print c, ' '} | |
puts "문장을 거꾸로 출력하여 보자" | |
puts poor_string.reverse | |
puts "문장이 Ji Sung Park 으로 시작하는지 알아보자" | |
puts poor_string.start_with?("Ji Sung Park") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment