Scala string
1. String 기본
var string1 = "I am a string"
var string2 = "I'm d string"
var string3 = "Put \" quotes\" by escaping"
var string4 = "Special \t characters \n insert"
var string5 = """
Hello
String
World!
"""
var myLanguage = "Scala"
var myExperience = 7
var myString = s"I love $myLanguage"
import java.time.Year
val thisYear = Year.now.getValue
var myLanguage = "Scala"
var myExperience - 7
var myString1 = s"I love $myLanguage."
var myString2 = s"I started learning it in ${thisYear - myExperience}"
var numQ = 56
var numC = 53
var resultStr = f"""You got $numC questions out of
$numQ correct. Your score was
${numC.toFloat/numQ.toFloat*100}%.2f%%"""
var string5 = "Use \n to print nuw lines"
var string6 = "Use \\n to print nuw lines"
var jsonString1 = "{\"key1\": \"value1\"}"
var jsonString2 = """
{"key1": "value1",
"key2":"value2",
"key3":"value3"}
"""
var jsonString3 =
"""
|{"key1":"value1",
| "key2":"value2",
| "key3":"value3"}
""".stripMargin
import java.time.Year
val thisYear = Year.now.getValue
var myLanguage = "Scala"
var myExperience = 7
var myString1 = s"I love $myLanguage."
var myString2 = s"I started learning it in ${thisYear - myExperience}"
var numQuestions = 56
var numCorrect = 53
var resultStr = f"""You got $numCorrect questions out of
$numQuestions correct. Your score was
${numCorrect.toFloat/numQuestions.toFloat*100}%.2f%%"""
var string5 = raw"You cat print a new line with \n"
구분 | 설명 | |
---|---|---|
%c | character | |
%d | decimal (integer) number (base 10) | |
%e | exponential floating-point number | |
%f | floating-point number | |
%i | integer (base 10) | |
%o | octal number (base 8) | |
%s | a string of characters | |
%u | unsigned decimal (integer) number | |
%x | unmber in hexadecimal (base 16) | |
%% | print a percent sign | |
\% | print a percent sign |
Pattern | Matches | |
---|---|---|
abc... | Letters | |
123... | Digits | |
\d | Any digit | |
\D | Any non-digit character | |
. | Any character | |
\. | Literal period | |
[abc] | a, b, pr c | |
[^abc] | NOT a, b, nor c | |
[a-z] | Characters a to z | |
\w | Any alphanumeric character | |
\W | Any non-alphanumeric character | |
{m} | m repetitions | |
* | Zero or more repetitions | </tr> |
+ | One or more repetitions | |
? | Optional character | |
\s | Any whitespace character | |
\S | Any non-whitespace character | |
(...) | Capture group | </tr> |
(abc|def) | abc or def |