字串資料類型
string 資料類型代表一連串零或多個 Unicode 字元。
- 在內部,字串是以 UTF-8編碼。 在汲取時,無效 (non-UTF8) 字元會取代為 U + FFFD Unicode 取代字元。
- KQL 沒有相當於單一字元的資料類型。 單一字元以長度為 1 的字串表示。
- 雖然
string資料類型本身對字串長度沒有預先定義的限制,但實際實作可以自由限制個別值。 通常,字串限制為 1MB (使用 UTF-8 編碼進行測量)。
字串文字
有數種方法可以將查詢文字中 string 資料類型的文字編碼:
- 用雙引號 (
") 括住字串:"This is a string literal. Single quote characters (') don't require escaping. Double quote characters (") are escaped by a backslash (\)." - 用單引號 (
') 括住字串:'Another string literal. Single quote characters (') require escaping by a backslash (\). Double quote characters (") do not require escaping.'
在上述兩種表示法中,反斜線 (\) 字元表示跳出。 反斜線用來跳出含括引號字元、跳格字元 (\t)、換行字元 (\n) 及本身 (\\)。
換行字元 (\n) 和傳回字元 (\r) 不能併入為字串文字的一部分,必須以引號括住。 另請參閱 多行字串文字。
Verbatim 字串文字-目前不受支援
也支援逐項字串文字。 在此形式中,反斜線字元 (\) 代表其本身,而不是作為跳出字元。
- 以雙引號 (
") 括住:@"This is a verbatim string literal that ends with a backslash\." - 以單引號 (
') 括住:@'This is a verbatim string literal that ends with a backslash\.'
換行字元 (\n) 和傳回字元 (\r) 不能併入為字串文字的一部分,必須以引號括住。 另請參閱 多行字串文字。
剪接字串文字-目前不支援
兩個以上字串文字會自動結合,以在查詢中形成新的字串文字 (如果它們之間沒有任何內容) ,或只以空格和註解來區隔它們。
例如,下列表示式都產生長度為 13 的字串:
print strlen("Hello"', '@"world!"); // Nothing between them
print strlen("Hello" ', ' @"world!"); // Separated by whitespace only
print strlen("Hello"
// Comment
', '@"world!"); // Separated by whitespace and a comment
多行字串文字-目前不受支援
多行字串文字是指換行 (\n) 和傳回 (\r) 字元不需要跳出的字串文字。
- 多行字串文字一律出現在兩次出現的 "triple-backtick chord" (` ` `) 之間。
- 多行字串文字不支援跳出字元。 與 逐項字串文字類似,多行字串文字容許換行及傳回字元。
- 多行字串文字不支援模糊化。
範例
// Simple string notation
print s1 = 'some string', s2 = "some other string"
// Strings that include single or double-quotes can be defined as follows
print s1 = 'string with " (double quotes)',
s2 = "string with ' (single quotes)"
// Strings with '\' can be prefixed with '@' (as in c#)
print myPath1 = @'C:\Folder\filename.txt'
// Escaping using '\' notation
print s = '\\n.*(>|\'|=|\")[a-zA-Z0-9/+]{86}=='
// Encode a C# program in a Kusto multi-line string
print program=```
public class Program {
public static void Main() {
System.Console.WriteLine("Hello!");
}
}```
可以看出,當字串以雙引號 (") 括住時,單引號 (') 字元不需要跳出,也不需要跳出。 此方法可讓您更容易根據環境定義來引用字串。
模糊化字串文字-目前不受支援
系統會追蹤查詢並儲存它們,以進行遙測及分析。 例如,叢集擁有者可以使用查詢文字。 如果查詢文字包含密鑰資訊 (例如密碼) ,則可能會洩漏應該保密的資訊。 為了防止發生這類洩漏,查詢作者可以將特定的字串文字標示為 模糊化字串文字。 查詢文字中的這類文字會自動取代為一些星號 (*) 字元,因此無法用於稍後的分析。
附註
將包含密鑰資訊的所有字串文字標示為模糊化字串文字。
透過採用「一般」字串文字,並在其前面附加 h 或 H 字元,可以形成模糊化字串文字。
例如:
h'hello'
h@'world'
h"hello"
在許多情況下,只有字串文字的一部分是密鑰。 在這些情況下,請將文字分割成非機密部分和機密部分。 然後,只將秘密部分標示為模糊化。
例如:
print x="https://contoso.blob.core.windows.net/container/blob.txt?"
h'sv=2012-02-12&se=2013-04-13T0...'