LoginSignup
0
0

More than 5 years have passed since last update.

Visual Studio | WPF > C# > string > @ > @-quoted 形式 > Pythonのraw stringに相当? | link: C++のRaw String Literal | link: bashの"--"

Last updated at Posted at 2017-12-11
動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

//コマンドライン引数に「"C:\test\1.txt"」を指定してメモ帳を起動する
System.Diagnostics.Process.Start("notepad.exe", @"""C:\test\1.txt""");

上記記載の中で「@」というのを知らなかった。

C# の string では「@(アットマーク)」の意味を知っていると便利 @ ゆめとちぼーとげんじつと

で、「@」を利用すると次の様に書くことができ、エスケープを行わずに「/」を文字列に含められるので、パスを指定したい場合などに可読性が高く、便利に使えます。

公式のドキュメントは以下だろうか。
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/keywords/string

リテラル文字列は string 型であり、二重引用符で囲む形式と、@-quoted 形式の 2 とおりがあります。

公式のドキュメント(英語版)
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/string

String literals are of type string and can be written in two forms, quoted and @-quoted.

最初に掲載のリンクのコードは二重引用符の数が多いように思う。
(二重引用符を前後に足した文字列を渡すようになっている)。
以下のコードで動作することを確認している。

System.Diagnostics.Process.Start("notepad.exe", @"C:\test\1.txt");

Python > raw strings

Pythonのraw stringsが近いだろうか。

文字列リテラルとバイト列リテラルの両方は、任意で文字 'r' または 'R' をプレフィックスに持つことができます; そのような文字列は raw strings と呼ばれ、バックスラッシュをリテラル文字として扱います。

Bash > "--"

(追記 2018/01/12)

@tukiyo3 さんの記事: 昨日〜9日前までの日付を空白区切りで返すサンプル
において、
@nakataSyunsuke さんと@tukiyo3 さんにbashの"--"について教えていただきました。

情報感謝です。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0