Swift Learning-演算子&文字列
3799 ワード
Head
本文は基本的にswift翻訳から勉強して、メモを取りましょう.
Contentユニット比較 連結Null演算子
3.区間
4.文字列
改行する特殊文字 拡張文字区切り記号 挿入&切り取り文字列
End
ますます怠惰になってきた........(
本文は基本的にswift翻訳から勉強して、メモを取りましょう.
Content
// 1.
//
// , , 。 ,
let x = (3,"c");
let y = (3,"bfffsdfsdfsdfsdsdfsdfsdasdfasfffffdvcxcxvc");
if x > y {
print("x > y");
} else if x == y {
print("x == y");
} else if x < y{
print("x < y");
}
let a : Int? = Int("123a");
print(a ?? 2); // a != nil ? a! : 2
3.区間
// 3.1 1...5
for index in 1...5 {
print(index,terminator: ",");
}
print("");
// 3.2
for index in 1..<5 {
print(index,terminator:",");
}
print("");
// 3.3
let names = ["Anna", "Alex", "Brian", "Jack"];
for index in names[1...2] {
print(index,terminator:",");
}
print("");
for index in names[0..
4.文字列
// 4.1 - """
let quotation = """
The White Rabbit put on his spectacles. "Where shall I begin,
please your Majesty?" he asked.
"Begin at the beginning," the King said gravely, "and go on
till you come to the end; then stop."
"""
print(quotation);
改行する
// 4.3 \
let softWrappedQuotation = """
The White Rabbit put on his spectacles. "Where shall I begin, \
please your Majesty?" he asked.
"Begin at the beginning," the King said gravely, "and go on \
till you come to the end; then stop."
"""
print(softWrappedQuotation);
\0 ( ), \\ ( ), \t ( ),
( ), \r( ), \" ( ) \' ( ); Unicode , \u{n}, n 1-8 Unicode 16 。
let spec = ["
","\0","\\","\t","\"","\r","\'","\u{1F496}"];
for item in spec {
print(item);
}
print("");
print(#"hahahahha\#nhhheehhehehe"#);
let string1 = "aaaaaa";
let string2 = string1;
print(Unmanaged.passUnretained(string1 as AnyObject).toOpaque());
print(Unmanaged.passUnretained(string2 as AnyObject).toOpaque());
let characterArr : [Character] = ["1","2","!","
",""];
let charaString : String? = String(characterArr);
print(charaString ?? "");
let multiplier = 3;
print("\(multiplier) times 2.5 is \(Double(multiplier) * 2.5) ")
//
var welcome = "hello";
welcome.insert("!", at: welcome.endIndex);
print(welcome);
welcome.insert(contentsOf : " world", at: welcome.index(before: welcome.endIndex));
print(welcome);
//
//
welcome = welcome.substring(to: welcome.firstIndex(of: " ")!);
print(welcome);
let index = welcome.firstIndex(of: "l") ?? welcome.endIndex;
let subWelcome = welcome[..
End
ますます怠惰になってきた........(