Comprehensive Rust(繁体中文)more detail later. • Edit the examples above to show the compiler error when the pattern doesn't match the value being matched on. 8.5 練習:巢狀陣列 陣列可包含其他陣列: let array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; minutes 12.1 Matching Values The match keyword lets you match a value against one or more patterns. The comparisons are done from top to bottom and the first match wins. 模式可以是簡單的值,類似 C 和 C++ 中的 switch: switch: fn main() { let input = 'x'; match input { 'q' => println!("Quitting"), 'a' | 's' | 'w' | 'd' => println!("Moving around"), '0'..='9' => println!("Number input"), key if key.is_lowercase() =>0 码力 | 358 页 | 1.41 MB | 10 月前3
julia 1.10.10whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") end If a regular expression does match, the value returned by match is a RegexMatch0 码力 | 1692 页 | 6.34 MB | 3 月前3
Julia 1.10.9whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") end If a regular expression does match, the value returned by match is a RegexMatch0 码力 | 1692 页 | 6.34 MB | 3 月前3
Julia 1.11.4whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2007 页 | 6.73 MB | 3 月前3
Julia 1.11.5 Documentationwhether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2007 页 | 6.73 MB | 3 月前3
Julia 1.11.6 Release Noteswhether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2007 页 | 6.73 MB | 3 月前3
Julia 1.12.0 RC1whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2057 页 | 7.44 MB | 3 月前3
Julia 1.12.0 Beta4whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2057 页 | 7.44 MB | 3 月前3
Julia 1.12.0 Beta3whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2057 页 | 7.44 MB | 3 月前3
julia 1.12.0 beta1whether a match for the given regex occurs in the string. Commonly, however, one wants to know not just whether a string matched, but also how it matched. To capture this information about a match, use the the match function instead: julia> match(r"^\s*(?:#|$)", "not a comment") julia> match(r"^\s*(?:#|$)", "# a comment") RegexMatch("#") If the regular expression does not match the given string, match programmatically: m = match(r"^\s*(?:#|$)", line) if m === nothing println("not a comment") else println("blank or comment") endCHAPTER 8. STRINGS 64 If a regular expression does match, the value returned0 码力 | 2047 页 | 7.41 MB | 3 月前3
共 22 条
- 1
- 2
- 3













