|
3 | 3 | using System.Text.RegularExpressions;
|
4 | 4 | using System.Threading;
|
5 | 5 |
|
6 |
| -public class Example |
| 6 | +public class CultureExample |
7 | 7 | {
|
8 |
| - public static void Main() |
9 |
| - { |
10 |
| - ShowIllegalAccess(); |
11 |
| - Console.WriteLine("-----"); |
12 |
| - ShowNoAccess(); |
13 |
| - } |
14 |
| - |
15 |
| - private static void ShowIllegalAccess() |
16 |
| - { |
17 |
| - // <Snippet14> |
18 |
| - CultureInfo defaultCulture = Thread.CurrentThread.CurrentCulture; |
19 |
| - Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR"); |
20 |
| - |
21 |
| - string input = "file://c:/Documents.MyReport.doc"; |
22 |
| - string pattern = "FILE://"; |
23 |
| - |
24 |
| - Console.WriteLine("Culture-sensitive matching ({0} culture)...", |
25 |
| - Thread.CurrentThread.CurrentCulture.Name); |
26 |
| - if (Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase)) |
27 |
| - Console.WriteLine("URLs that access files are not allowed."); |
28 |
| - else |
29 |
| - Console.WriteLine("Access to {0} is allowed.", input); |
30 |
| - |
31 |
| - Thread.CurrentThread.CurrentCulture = defaultCulture; |
32 |
| - // The example displays the following output: |
33 |
| - // Culture-sensitive matching (tr-TR culture)... |
34 |
| - // Access to file://c:/Documents.MyReport.doc is allowed. |
35 |
| - // </Snippet14> |
36 |
| - } |
37 |
| - |
38 |
| - private static void ShowNoAccess() |
39 |
| - { |
40 |
| - // <Snippet15> |
41 |
| - CultureInfo defaultCulture = Thread.CurrentThread.CurrentCulture; |
42 |
| - Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR"); |
43 |
| - |
44 |
| - string input = "file://c:/Documents.MyReport.doc"; |
45 |
| - string pattern = "FILE://"; |
46 |
| - |
47 |
| - Console.WriteLine("Culture-insensitive matching..."); |
48 |
| - if (Regex.IsMatch(input, pattern, |
49 |
| - RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) |
50 |
| - Console.WriteLine("URLs that access files are not allowed."); |
51 |
| - else |
52 |
| - Console.WriteLine("Access to {0} is allowed.", input); |
53 |
| - |
54 |
| - Thread.CurrentThread.CurrentCulture = defaultCulture; |
55 |
| - // The example displays the following output: |
56 |
| - // Culture-insensitive matching... |
57 |
| - // URLs that access files are not allowed. |
58 |
| - // </Snippet15> |
59 |
| - } |
| 8 | + public static void Main() |
| 9 | + { |
| 10 | + ShowIllegalAccess(); |
| 11 | + Console.WriteLine("-----"); |
| 12 | + ShowNoAccess(); |
| 13 | + } |
| 14 | + |
| 15 | + private static void ShowIllegalAccess() |
| 16 | + { |
| 17 | + // <Snippet14> |
| 18 | + CultureInfo defaultCulture = Thread.CurrentThread.CurrentCulture; |
| 19 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR"); |
| 20 | + |
| 21 | + string input = "file://c:/Documents.MyReport.doc"; |
| 22 | + string pattern = "FILE://"; |
| 23 | + |
| 24 | + Console.WriteLine("Culture-sensitive matching ({0} culture)...", |
| 25 | + Thread.CurrentThread.CurrentCulture.Name); |
| 26 | + if (Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase)) |
| 27 | + Console.WriteLine("URLs that access files are not allowed."); |
| 28 | + else |
| 29 | + Console.WriteLine("Access to {0} is allowed.", input); |
| 30 | + |
| 31 | + Thread.CurrentThread.CurrentCulture = defaultCulture; |
| 32 | + // The example displays the following output: |
| 33 | + // Culture-sensitive matching (tr-TR culture)... |
| 34 | + // Access to file://c:/Documents.MyReport.doc is allowed. |
| 35 | + // </Snippet14> |
| 36 | + } |
| 37 | + |
| 38 | + private static void ShowNoAccess() |
| 39 | + { |
| 40 | + // <Snippet15> |
| 41 | + CultureInfo defaultCulture = Thread.CurrentThread.CurrentCulture; |
| 42 | + Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR"); |
| 43 | + |
| 44 | + string input = "file://c:/Documents.MyReport.doc"; |
| 45 | + string pattern = "FILE://"; |
| 46 | + |
| 47 | + Console.WriteLine("Culture-insensitive matching..."); |
| 48 | + if (Regex.IsMatch(input, pattern, |
| 49 | + RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) |
| 50 | + Console.WriteLine("URLs that access files are not allowed."); |
| 51 | + else |
| 52 | + Console.WriteLine("Access to {0} is allowed.", input); |
| 53 | + |
| 54 | + Thread.CurrentThread.CurrentCulture = defaultCulture; |
| 55 | + // The example displays the following output: |
| 56 | + // Culture-insensitive matching... |
| 57 | + // URLs that access files are not allowed. |
| 58 | + // </Snippet15> |
| 59 | + } |
60 | 60 | }
|
0 commit comments