카테고리 없음

[코드아카데미] Putting the Form in Formatter (6/7) 스트링 메소드를 활용하기

tomato23 2014. 9. 9. 14:35

Putting the Form in Formatter (6/7)

 

Formatting with String Methods

스트림 메소드로 자료 형태 변환하기

Great! Now we've got our output, but as you can see, we haven't used string methods to properly capitalize everything yet.

좋아! 이제 우리는 출력을 얻었어. 그런데 니가 보다시피 우리는 아직 모든 것에 적절한 대문자화를 위한 문자열 메소드를 쓰지 않았어.    

print "This is my question?"
answer = gets.chomp
answer2 = answer.capitalize 
answer.capitalize!

 

 

 

  1. First we introduce one new method, capitalize, here. It capitalizes the first letter of a string and makes the rest of the letters lower case. We assign the result to answer2 먼저 우리는 여기서 대문자화에 대한 새로운 매쏘드를 하나 소개할 거야, 이건 첫번째 문자를 대문자화해 그리고 나머지 문자들을 소문자로 바꾸지. 우리는 이 메소드를 적용한 결과를 aswer2에 담고 있어.
  2. The next line might look a little strange, we don't assign the result of capitalize to a variable. Instead you might notice the ! at the end of capitalize. This modifies the value contained within the variable answer itself. The next time you use the variable answer you will get the results of answer.capitalize 그 다음 라인은 조금 이상해보일지도 몰라, 우리는 capitalize 메소드의 결과를 변수에 담지 않았어. 대신에 넌 capitalize 메소드의 뒤에 있는 따옴표를 발견할 수 있어.  이건 answer 변수의 변경 값을 바로 그 자신에 대입 하게 만들고 있어. 다음에 변수 answer를 쓰게 되면 넌 answer.capitize 의 결과 값을 얻게 될 거야.

 

반응형