玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
【C#】0324
今日進度:
C# String:
Access Strings, Special Characters
.
荒廢了好多天ㄛ
今天進度也少少的
latest #17
掰噗~
1 months ago
哇哩咧 :-&
復習復習:
using System;
namespace 應該還記得ㄅ
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“好險第二行差點記不起來ㄛ”);
}
}
}
立即下載
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
接上

6. 字串變數[ ]:擷取指定位數的字元
-
string myString=“Hello World”;
Console.WriteLine(myString[0]);
// 擷取第一位:H
Console.WriteLine(myString[1]);
// 擷取第二位:e
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
7. 字串變數.IndexOf(“ “):
找到擷取字母是第幾位
-
Console.WriteLine(myString.IndexOf(“W”));
// =7(第7位字元)
8. 字串變數.Substring():
從指定的字元位置開始得到新字串
常與 IndexOf變成組合技一起使用
-
int charPos = myString.IndexOf(“W”);
string secString = myString.Substring(charPos);
Console.WriteLine(secString);
// = World
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
試著合併以上三行
Console.WriteLine(myString.Substring(myString.IndexOf(“W”)));
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
也可以用座標表示新字串範圍
-
string bio = “Kalafina is special.”
string groupName = bio.Substring(0,8);
Console.WriteLine(groupName);
// = Kalafina
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
9. 利用 \ (backslash) :
顯示 / 或 ‘ 或 “
還有一些特殊妙用(?)
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
\”
-
Console.WriteLine(“\”Kalafina\”是個三人組合”);
// = Kalafina是個三人組合
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
\’
-
Console.WriteLine(“It\’s a wonderful day.”);
// = Its a wonderful day.
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
\\
-
Console.WriteLine(“The character \\ is called backslash.”);
// = The character \ is called backslash.
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
\n:換行
-
Console.WriteLine(“Hello \nWorld”);
// =
Hello
World
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
\t:右退一格tab
-
Console.WriteLine(“Hello \tWorld”);
// = Hello World
\b:退格鍵backspace
-
Console.WriteLine(“Hel\blo World”);
// = Helo World
back to top