· 8 years ago · Nov 22, 2017, 09:58 AM
1string query = "SELECT foo, bar"
2+ " FROM table"
3+ " WHERE id = 42";
4
5<<<BLOCK
6
7BLOCK;
8
9string query = @"SELECT foo, bar
10FROM table
11WHERE id = 42";
12
13string query = @"SELECT foo, bar
14FROM table
15WHERE name = 'ab'";
16
17string quote = @"Jon said, ""This will work,"" - and it did!";
18
19// this would give a format exception
20string.Format(@"<script> function test(x)
21 { return x * {0} } </script>", aMagicValue)
22// this contrived example would work
23string.Format(@"<script> function test(x)
24 {{ return x * {0} }} </script>", aMagicValue)
25
26var someString = @"The
27quick
28brown
29fox...";
30
31var someString = String.Join(
32 Environment.NewLine,
33 "The",
34 "quick",
35 "brown",
36 "fox...");
37
38string camlCondition = $@"
39<Where>
40 <Contains>
41 <FieldRef Name='Resource'/>
42 <Value Type='Text'>{(string)parameter}</Value>
43 </Contains>
44</Where>";
45
46string query = "SELECT foo, bar"
47 + " FROM table"
48 + " WHERE id = 42";
49
50private string createTableQuery = "";
51
52 void createTable(string tableName)
53 {
54
55 createTableQuery = @"CREATE TABLE IF NOT EXISTS
56 ["+ tableName + @"] (
57 [ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
58 [Key] NVARCHAR(2048) NULL,
59 [Value] VARCHAR(2048) NULL
60 )";
61 }
62
63var myString = String.Format(
64 "hello " +
65 "world" +
66 " i am {0}" +
67 " and I like {1}.",
68 animalType,
69 animalPreferenceType
70);
71// hello world i am a pony and I like other ponies.
72
73private static String ReverseString(String str)
74 {
75 int word_length = 0;
76 String result = "";
77 for (int i = 0; i < str.Length; i++)
78 {
79 if (str[i] == ' ')
80 {
81 result = " " + result;
82 word_length = 0;
83 }
84 else
85 {
86 result = result.Insert(word_length, str[i].ToString());
87 word_length++;
88 }
89 }
90 return result;
91 }
92//NASSIM LOUCHANI
93 public static string SplitLineToMultiline(string input, int rowLength)
94 {
95 StringBuilder result = new StringBuilder();
96 StringBuilder line = new StringBuilder();
97
98 Stack<string> stack = new Stack<string>(ReverseString(input).Split(' '));
99
100 while (stack.Count > 0)
101 {
102 var word = stack.Pop();
103 if (word.Length > rowLength)
104 {
105 string head = word.Substring(0, rowLength);
106 string tail = word.Substring(rowLength);
107
108 word = head;
109 stack.Push(tail);
110 }
111
112 if (line.Length + word.Length > rowLength)
113 {
114 result.AppendLine(line.ToString());
115 line.Clear();
116 }
117
118 line.Append(word + " ");
119 }
120
121 result.Append(line);
122 return result.ToString();
123 }