├── .gitignore
├── L01.Ascii
├── L01.Ascii.csproj
└── Program.cs
├── L02.EncodingAndUnicode
├── L02.EncodingAndUnicode.csproj
└── Program.cs
├── L03.Instantiation
├── L03.Instantiation.csproj
└── Program.cs
├── L04.L04.UnicodeAndStringComparison
├── L04.UnicodeAndStringComparison.csproj
└── Program.cs
├── L05.InternPool
├── L05.InternPool.csproj
└── Program.cs
├── L06.StringMethods
├── L06.StringMethods.csproj
└── Program.cs
└── Metigator44.sln
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # Tye
66 | .tye/
67 |
68 | # ASP.NET Scaffolding
69 | ScaffoldingReadMe.txt
70 |
71 | # StyleCop
72 | StyleCopReport.xml
73 |
74 | # Files built by Visual Studio
75 | *_i.c
76 | *_p.c
77 | *_h.h
78 | *.ilk
79 | *.meta
80 | *.obj
81 | *.iobj
82 | *.pch
83 | *.pdb
84 | *.ipdb
85 | *.pgc
86 | *.pgd
87 | *.rsp
88 | *.sbr
89 | *.tlb
90 | *.tli
91 | *.tlh
92 | *.tmp
93 | *.tmp_proj
94 | *_wpftmp.csproj
95 | *.log
96 | *.vspscc
97 | *.vssscc
98 | .builds
99 | *.pidb
100 | *.svclog
101 | *.scc
102 |
103 | # Chutzpah Test files
104 | _Chutzpah*
105 |
106 | # Visual C++ cache files
107 | ipch/
108 | *.aps
109 | *.ncb
110 | *.opendb
111 | *.opensdf
112 | *.sdf
113 | *.cachefile
114 | *.VC.db
115 | *.VC.VC.opendb
116 |
117 | # Visual Studio profiler
118 | *.psess
119 | *.vsp
120 | *.vspx
121 | *.sap
122 |
123 | # Visual Studio Trace Files
124 | *.e2e
125 |
126 | # TFS 2012 Local Workspace
127 | $tf/
128 |
129 | # Guidance Automation Toolkit
130 | *.gpState
131 |
132 | # ReSharper is a .NET coding add-in
133 | _ReSharper*/
134 | *.[Rr]e[Ss]harper
135 | *.DotSettings.user
136 |
137 | # TeamCity is a build add-in
138 | _TeamCity*
139 |
140 | # DotCover is a Code Coverage Tool
141 | *.dotCover
142 |
143 | # AxoCover is a Code Coverage Tool
144 | .axoCover/*
145 | !.axoCover/settings.json
146 |
147 | # Coverlet is a free, cross platform Code Coverage Tool
148 | coverage*.json
149 | coverage*.xml
150 | coverage*.info
151 |
152 | # Visual Studio code coverage results
153 | *.coverage
154 | *.coveragexml
155 |
156 | # NCrunch
157 | _NCrunch_*
158 | .*crunch*.local.xml
159 | nCrunchTemp_*
160 |
161 | # MightyMoose
162 | *.mm.*
163 | AutoTest.Net/
164 |
165 | # Web workbench (sass)
166 | .sass-cache/
167 |
168 | # Installshield output folder
169 | [Ee]xpress/
170 |
171 | # DocProject is a documentation generator add-in
172 | DocProject/buildhelp/
173 | DocProject/Help/*.HxT
174 | DocProject/Help/*.HxC
175 | DocProject/Help/*.hhc
176 | DocProject/Help/*.hhk
177 | DocProject/Help/*.hhp
178 | DocProject/Help/Html2
179 | DocProject/Help/html
180 |
181 | # Click-Once directory
182 | publish/
183 |
184 | # Publish Web Output
185 | *.[Pp]ublish.xml
186 | *.azurePubxml
187 | # Note: Comment the next line if you want to checkin your web deploy settings,
188 | # but database connection strings (with potential passwords) will be unencrypted
189 | *.pubxml
190 | *.publishproj
191 |
192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
193 | # checkin your Azure Web App publish settings, but sensitive information contained
194 | # in these scripts will be unencrypted
195 | PublishScripts/
196 |
197 | # NuGet Packages
198 | *.nupkg
199 | # NuGet Symbol Packages
200 | *.snupkg
201 | # The packages folder can be ignored because of Package Restore
202 | **/[Pp]ackages/*
203 | # except build/, which is used as an MSBuild target.
204 | !**/[Pp]ackages/build/
205 | # Uncomment if necessary however generally it will be regenerated when needed
206 | #!**/[Pp]ackages/repositories.config
207 | # NuGet v3's project.json files produces more ignorable files
208 | *.nuget.props
209 | *.nuget.targets
210 |
211 | # Microsoft Azure Build Output
212 | csx/
213 | *.build.csdef
214 |
215 | # Microsoft Azure Emulator
216 | ecf/
217 | rcf/
218 |
219 | # Windows Store app package directories and files
220 | AppPackages/
221 | BundleArtifacts/
222 | Package.StoreAssociation.xml
223 | _pkginfo.txt
224 | *.appx
225 | *.appxbundle
226 | *.appxupload
227 |
228 | # Visual Studio cache files
229 | # files ending in .cache can be ignored
230 | *.[Cc]ache
231 | # but keep track of directories ending in .cache
232 | !?*.[Cc]ache/
233 |
234 | # Others
235 | ClientBin/
236 | ~$*
237 | *~
238 | *.dbmdl
239 | *.dbproj.schemaview
240 | *.jfm
241 | *.pfx
242 | *.publishsettings
243 | orleans.codegen.cs
244 |
245 | # Including strong name files can present a security risk
246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
247 | #*.snk
248 |
249 | # Since there are multiple workflows, uncomment next line to ignore bower_components
250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
251 | #bower_components/
252 |
253 | # RIA/Silverlight projects
254 | Generated_Code/
255 |
256 | # Backup & report files from converting an old project file
257 | # to a newer Visual Studio version. Backup files are not needed,
258 | # because we have git ;-)
259 | _UpgradeReport_Files/
260 | Backup*/
261 | UpgradeLog*.XML
262 | UpgradeLog*.htm
263 | ServiceFabricBackup/
264 | *.rptproj.bak
265 |
266 | # SQL Server files
267 | *.mdf
268 | *.ldf
269 | *.ndf
270 |
271 | # Business Intelligence projects
272 | *.rdl.data
273 | *.bim.layout
274 | *.bim_*.settings
275 | *.rptproj.rsuser
276 | *- [Bb]ackup.rdl
277 | *- [Bb]ackup ([0-9]).rdl
278 | *- [Bb]ackup ([0-9][0-9]).rdl
279 |
280 | # Microsoft Fakes
281 | FakesAssemblies/
282 |
283 | # GhostDoc plugin setting file
284 | *.GhostDoc.xml
285 |
286 | # Node.js Tools for Visual Studio
287 | .ntvs_analysis.dat
288 | node_modules/
289 |
290 | # Visual Studio 6 build log
291 | *.plg
292 |
293 | # Visual Studio 6 workspace options file
294 | *.opt
295 |
296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
297 | *.vbw
298 |
299 | # Visual Studio LightSwitch build output
300 | **/*.HTMLClient/GeneratedArtifacts
301 | **/*.DesktopClient/GeneratedArtifacts
302 | **/*.DesktopClient/ModelManifest.xml
303 | **/*.Server/GeneratedArtifacts
304 | **/*.Server/ModelManifest.xml
305 | _Pvt_Extensions
306 |
307 | # Paket dependency manager
308 | .paket/paket.exe
309 | paket-files/
310 |
311 | # FAKE - F# Make
312 | .fake/
313 |
314 | # CodeRush personal settings
315 | .cr/personal
316 |
317 | # Python Tools for Visual Studio (PTVS)
318 | __pycache__/
319 | *.pyc
320 |
321 | # Cake - Uncomment if you are using it
322 | # tools/**
323 | # !tools/packages.config
324 |
325 | # Tabs Studio
326 | *.tss
327 |
328 | # Telerik's JustMock configuration file
329 | *.jmconfig
330 |
331 | # BizTalk build output
332 | *.btp.cs
333 | *.btm.cs
334 | *.odx.cs
335 | *.xsd.cs
336 |
337 | # OpenCover UI analysis results
338 | OpenCover/
339 |
340 | # Azure Stream Analytics local run output
341 | ASALocalRun/
342 |
343 | # MSBuild Binary and Structured Log
344 | *.binlog
345 |
346 | # NVidia Nsight GPU debugger configuration file
347 | *.nvuser
348 |
349 | # MFractors (Xamarin productivity tool) working folder
350 | .mfractor/
351 |
352 | # Local History for Visual Studio
353 | .localhistory/
354 |
355 | # BeatPulse healthcheck temp database
356 | healthchecksdb
357 |
358 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
359 | MigrationBackup/
360 |
361 | # Ionide (cross platform F# VS Code tools) working folder
362 | .ionide/
363 |
364 | # Fody - auto-generated XML schema
365 | FodyWeavers.xsd
366 |
367 | ##
368 | ## Visual studio for Mac
369 | ##
370 |
371 |
372 | # globs
373 | Makefile.in
374 | *.userprefs
375 | *.usertasks
376 | config.make
377 | config.status
378 | aclocal.m4
379 | install-sh
380 | autom4te.cache/
381 | *.tar.gz
382 | tarballs/
383 | test-results/
384 |
385 | # Mac bundle stuff
386 | *.dmg
387 | *.app
388 |
389 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
390 | # General
391 | .DS_Store
392 | .AppleDouble
393 | .LSOverride
394 |
395 | # Icon must end with two \r
396 | Icon
397 |
398 |
399 | # Thumbnails
400 | ._*
401 |
402 | # Files that might appear in the root of a volume
403 | .DocumentRevisions-V100
404 | .fseventsd
405 | .Spotlight-V100
406 | .TemporaryItems
407 | .Trashes
408 | .VolumeIcon.icns
409 | .com.apple.timemachine.donotpresent
410 |
411 | # Directories potentially created on remote AFP share
412 | .AppleDB
413 | .AppleDesktop
414 | Network Trash Folder
415 | Temporary Items
416 | .apdisk
417 |
418 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
419 | # Windows thumbnail cache files
420 | Thumbs.db
421 | ehthumbs.db
422 | ehthumbs_vista.db
423 |
424 | # Dump file
425 | *.stackdump
426 |
427 | # Folder config file
428 | [Dd]esktop.ini
429 |
430 | # Recycle Bin used on file shares
431 | $RECYCLE.BIN/
432 |
433 | # Windows Installer files
434 | *.cab
435 | *.msi
436 | *.msix
437 | *.msm
438 | *.msp
439 |
440 | # Windows shortcuts
441 | *.lnk
442 |
443 | # JetBrains Rider
444 | .idea/
445 | *.sln.iml
446 |
447 | ##
448 | ## Visual Studio Code
449 | ##
450 | .vscode/*
451 | !.vscode/settings.json
452 | !.vscode/tasks.json
453 | !.vscode/launch.json
454 | !.vscode/extensions.json
455 |
--------------------------------------------------------------------------------
/L01.Ascii/L01.Ascii.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 |
7 |
8 |
--------------------------------------------------------------------------------
/L01.Ascii/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Text;
4 |
5 | namespace Metigator44.L01
6 | {
7 | internal class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | for (byte c = 0; c < 255; ++c)
12 | {
13 | char ch = (char)c;
14 | string dec = c.ToString().PadLeft(3, '0');
15 | string hex = c.ToString("X");
16 | string binary = Convert.ToString(c, 2).PadLeft(8, '0');
17 | Console.WriteLine($"{dec,-12} {binary,-12} {hex,-12} {ch,-12}");
18 | }
19 |
20 | Console.ReadKey();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/L02.EncodingAndUnicode/L02.EncodingAndUnicode.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/L02.EncodingAndUnicode/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualBasic;
2 | using System;
3 | using System.Collections;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Metigator44.L02
8 | {
9 | internal class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
14 | Encoding chinese = Encoding.GetEncoding("GB18030");
15 | Console.WriteLine("大");
16 |
17 | Task.Run(() => GetDataUTF8Format());
18 | Console.ReadKey();
19 | }
20 |
21 | static async Task GetDataAssciFormat()
22 | {
23 | var path = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}";
24 | var filePath = $"{path}\\asciiNewsContent.txt";
25 |
26 | using (var client = new HttpClient())
27 | {
28 | Uri uri = new Uri("https://aljazeera.net/search/feed");
29 | using (HttpResponseMessage response = await client.GetAsync(uri))
30 | {
31 | var byteArray = await response.Content.ReadAsByteArrayAsync();
32 | string result = Encoding.ASCII.GetString(byteArray);
33 | File.WriteAllText(filePath, result);
34 | }
35 | }
36 | }
37 |
38 | static async Task GetDataUTF8Format()
39 | {
40 | var path = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}";
41 | var filePath = $"{path}\\utf8NewsContent.txt";
42 |
43 | using (var client = new HttpClient())
44 | {
45 | Uri uri = new Uri("https://aljazeera.net/search/feed");
46 | using (HttpResponseMessage response = await client.GetAsync(uri))
47 | {
48 | var byteArray = await response.Content.ReadAsByteArrayAsync();
49 | string result = Encoding.UTF8.GetString(byteArray);
50 | File.WriteAllText(filePath, result);
51 | }
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/L03.Instantiation/L03.Instantiation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | preview
7 | true
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/L03.Instantiation/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace Metigator44.L03
5 | {
6 | internal class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | //UsingQuotedStringLiterals();
11 |
12 | //UsingStringConstructor();
13 |
14 | //UsingRepeatingCharacter();
15 |
16 | //UsingPointerToSignedByte();
17 |
18 | //UsingAPointerToCharacterArray();
19 |
20 | //UsingConcatenation();
21 |
22 | //UsingCallingMethodThatReturnsString();
23 |
24 | //UsingFormattedString();
25 |
26 | //UsingVerbatimWithStringInterpolation();
27 |
28 | //UsingRawString();
29 |
30 | Console.ReadKey();
31 | }
32 |
33 |
34 |
35 | private static void UsingQuotedStringLiterals()
36 | {
37 | // Suited for strings that fit on a single line
38 |
39 | string str = "Metigator";
40 | Console.WriteLine(str);
41 | }
42 |
43 | private static void UsingStringConstructor()
44 | {
45 | // [2] using String Constructor (array of characters)
46 | char[] letters = { 'M', 'e', 't', 'i', 'g', 'a', 't', 'o', 'r' };
47 | string str = new string(letters);
48 | Console.WriteLine(str);
49 | }
50 |
51 | private static void UsingRepeatingCharacter()
52 | {
53 | // [3] // Create a string that consists of a character repeated 8 times.
54 | string str = new string('M', 8);
55 | Console.WriteLine(str);
56 | }
57 |
58 | private static void UsingPointerToSignedByte()
59 | {
60 | // [4] Create a string from a pointer to a signed byte array.
61 | // 'M' 'e' 't' 'i' 'g' 'a', 't', 'o' 'r'
62 | sbyte[] bytes = { 0x4D, 0x65, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6F, 0x72 };
63 | string str = null;
64 | // safe context (use pointer, allocation memory block,
65 | // call method using function pointer
66 | unsafe
67 | {
68 | // Pin the buffer to a fixed location in memory.
69 | fixed (sbyte* ptr = bytes)
70 | {
71 | str = new string(ptr);
72 | Console.WriteLine(str);
73 |
74 | }
75 | }
76 | }
77 |
78 | private static void UsingAPointerToCharacterArray()
79 | {
80 | // [5] Create a string from a pointer to a character array.
81 | char[] letters = { 'M', 'e', 't', 'i', 'g', 'a', 't', 'o', 'r' };
82 |
83 | string str = null;
84 | unsafe
85 | {
86 | fixed (char* pchars = letters)
87 | {
88 | // Create a string from a pointer to a character array.
89 | str = new string(pchars);
90 | Console.WriteLine(str);
91 | }
92 | }
93 | }
94 |
95 | private static void UsingConcatenation()
96 | {
97 | // [5] Using concatenation
98 | string str1 = "Meti" + "gator";
99 | string str2 = $"{"Meti"}{"gator"}"; // string interpolation
100 |
101 | Console.WriteLine($"str1 = {str1}");
102 | Console.WriteLine($"str2 = {str2}");
103 | }
104 |
105 | private static void UsingCallingMethodThatReturnsString()
106 | {
107 |
108 | string sentence = "I Love Metigator channel.";
109 |
110 | int startPos = sentence.IndexOf("Metigator"); // 7
111 |
112 | string str = sentence.Substring(startPos, 9); // string from 7,
113 |
114 | Console.WriteLine(str);
115 |
116 | }
117 |
118 | private static void UsingFormattedString()
119 | {
120 | // using formatted string will convert any object to string representation
121 | string customer = "Issam A";
122 | DateTime shippingDate = DateTime.Now; // yyyy-MM-dd hh:mm
123 | DateTime expectedDelivery = shippingDate.AddDays(7); // yyyy-MM-dd hh:mm
124 | decimal shippingCost = 29.99m;
125 |
126 | string str = String.Format(
127 | "\nDear {0}.," +
128 | "\n\nAt {1:t} on {1:D}, the order is on its way to you" +
129 | "\nIt's expected to be delivered at {2:t} on {2:D}, the order is on its way to you" +
130 | "\nShipping cost {3:c}."+
131 | "\n\t\t\tThanks for shopping with us!",
132 |
133 | customer, shippingDate, expectedDelivery, shippingCost);
134 | // 0 1 2 3
135 | Console.WriteLine(str);
136 | }
137 |
138 | private static void UsingVerbatimWithStringInterpolation()
139 | {
140 | string customer = "Issam A";
141 | DateTime shippingDate = DateTime.Now;
142 | DateTime expectedDelivery = shippingDate.AddDays(7);
143 | decimal shippingCost = 29.99m;
144 |
145 | string str = $@"Dear {customer},
146 |
147 | At {shippingDate:t} on {shippingDate:D}, the order is on its way to you
148 | It's expected to be delivered at {expectedDelivery:t} on {expectedDelivery:D}, the order is on its way to you
149 | Shipping cost {shippingCost:c}.
150 | Thanks for shopping with us!";
151 | Console.WriteLine(str);
152 | }
153 |
154 | private static void UsingRawString()
155 | {
156 | // Raw string starting from C# 11.0
157 | string str = """
158 |
166 | """;
167 |
168 | string str2 = """ this is a single line raw string""";
169 | Console.WriteLine(str);
170 | Console.WriteLine(str2);
171 |
172 | }
173 | }
174 | }
--------------------------------------------------------------------------------
/L04.L04.UnicodeAndStringComparison/L04.UnicodeAndStringComparison.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/L04.L04.UnicodeAndStringComparison/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Metigator44.L04
5 | {
6 | internal class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | // Unicode character -> code point
11 | // Code point a = "\u0061";
12 | // graphemes: multiple char object (base, combine) : a ̈
13 | // Also we have single chars that represent the graphems ä
14 |
15 |
16 | StreamWriter sw = new StreamWriter(@".\output.txt");
17 | string char1 = "\u0061"; // a
18 | string char2 = "\u0308"; // ̈
19 |
20 | sw.WriteLine(char1); // a
21 | sw.WriteLine(char2); // ̈
22 |
23 |
24 | string grapheme = "\u0061\u0308";
25 | sw.WriteLine(grapheme); // ä
26 |
27 |
28 | string singleChar = "\u00e4";
29 | sw.WriteLine(singleChar); // ä
30 |
31 | // representation are equal
32 | sw.WriteLine("{0} = {1} (Culture-sensitive): {2}", grapheme, singleChar,
33 | String.Equals(grapheme, singleChar,
34 | StringComparison.CurrentCulture)); // true
35 |
36 | sw.WriteLine("{0} = {1} (Ordinal): {2}", grapheme, singleChar,
37 | String.Equals(grapheme, singleChar,
38 | StringComparison.Ordinal)); // False
39 |
40 | sw.WriteLine("{0} = {1} (Normalized Ordinal): {2}", grapheme, singleChar,
41 | String.Equals(grapheme.Normalize(),
42 | singleChar.Normalize(),
43 | StringComparison.Ordinal)); // True
44 | sw.Close();
45 | }
46 |
47 | }
48 | }
--------------------------------------------------------------------------------
/L05.InternPool/L05.InternPool.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/L05.InternPool/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Metigator44.L05
4 | {
5 | internal class Program
6 | {
7 | public static void Main(string[] args)
8 | {
9 | // RunStringLiteralVsObject();
10 | // RunStringLiteralKey();
11 | // RunStringLiteralWithStringObjectComparison();
12 | RunStringIntern();
13 |
14 | Console.ReadKey();
15 |
16 | }
17 |
18 | public static void RunStringLiteralVsObject()
19 | {
20 | string s1 = "metigator"; // string literal
21 | string s2 = new string ("metigator"); // string object
22 |
23 |
24 | Console.WriteLine(s1 == s2); // true same content (string override equality value based)
25 | Console.WriteLine(s1.Equals(s2)); // true same content
26 |
27 | Console.WriteLine((Object)s1 == (Object)s2); // false two different reference
28 | Console.WriteLine(ReferenceEquals(s1, s2)); // false two different reference
29 |
30 | }
31 |
32 | public static void RunStringLiteralKey()
33 | {
34 | string s1 = "metigator"; // string literal
35 | string s2 = "aspnet"; // string literal
36 | string s3 = "meti" + "gator"; // string literal
37 |
38 |
39 |
40 | Console.WriteLine(s1 == s2); // false different content
41 | Console.WriteLine(ReferenceEquals(s1, s2)); // false two different reference
42 |
43 |
44 | Console.WriteLine(s1 == s3); // true same content
45 | Console.WriteLine(ReferenceEquals(s1, s3)); // true same reference
46 | }
47 |
48 | public static void RunStringLiteralWithStringObjectComparison()
49 | {
50 | string s1 = "metigator"; // string literal
51 | //string s11 = "metigator";
52 | string s2 = new string("metigator"); // string object
53 |
54 | Console.WriteLine(s1 == s2); // true, same content
55 |
56 | Console.WriteLine(ReferenceEquals(s1, s2)); // false different reference
57 |
58 | }
59 |
60 | public static void RunStringIntern()
61 | {
62 | string s1 = "metigator"; // string literal
63 |
64 | string s2 = new string("metigator"); // string object
65 |
66 | string s3 = String.Intern(s2); // string literal
67 |
68 | Console.WriteLine(s1 == s2); // true, same content
69 | Console.WriteLine(ReferenceEquals(s1, s2)); // false different reference
70 |
71 | Console.WriteLine(s2 == s3); // true, same content
72 | Console.WriteLine(ReferenceEquals(s2, s3)); // false different reference
73 |
74 | Console.WriteLine(s1 == s3); // true, same content
75 | Console.WriteLine(ReferenceEquals(s1, s3)); // true, same reference
76 |
77 |
78 | string str = "xyz";
79 |
80 | Console.WriteLine(str);
81 |
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/L06.StringMethods/L06.StringMethods.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/L06.StringMethods/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Metigator44.L06
5 | {
6 | internal class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | //RunCopyTo();
11 | // RunCompare();
12 | // RunStringFound();
13 | // RunStringFormat();
14 | // RunStringIsNullOrEmpty();
15 | // RunStringIsNullOrWhiteSpace();
16 | // RunStringModify();
17 | // RunToCase();
18 | // RunTrim();
19 | // RunToCharacterArray();
20 | // RunSplit();
21 | RunStringJoin();
22 | Console.ReadKey();
23 | }
24 |
25 |
26 |
27 | static void RunCopyTo()
28 | {
29 | string s1 = "metigator";
30 | char[] characters = { 'f', 'u', 'l', 'l', ' ', 's', 't', 'a', 'c', 'k', ' ',
31 | '?', '?', '?', '?', '?', '?', '?', '?', '?'};
32 |
33 | Console.WriteLine(characters);
34 |
35 | // copies count characters from the sourceIndex position of this instance
36 | // to the destinationIndex position of destination character array.
37 |
38 | s1.CopyTo(0, characters, 11, s1.Length);
39 |
40 | Console.WriteLine(characters);
41 | }
42 |
43 | static void RunCompare()
44 | {
45 | // ascii sort order (integer, capital, small)
46 | // a12Bc = 12Bac
47 |
48 | string s1 = "metigator";
49 | string s2 = "Metigator";
50 |
51 | // Compares two specified String objects and returns an integer
52 | // that indicates their relative position in the sort order.
53 | Console.WriteLine(string.Compare(s1, s2, true)); // 0
54 | Console.WriteLine(string.Compare(s1, s2, false)); // -1
55 | Console.WriteLine(string.Compare(s2, s1, false)); // 1
56 | }
57 |
58 | static void RunStringFound()
59 | {
60 | // ascii sort order (integer, capital, small)
61 | string s1 = "metigator";
62 |
63 | // Returns whether a specified character occurs within this string.
64 | Console.WriteLine(s1.Contains("gato")); // true
65 |
66 | // starts with the specified character.
67 | Console.WriteLine(s1.StartsWith("meti")); // true
68 |
69 | // ends with the specified character.
70 | Console.WriteLine(s1.EndsWith("torx")); // false
71 |
72 | // Reports the zero-based index of the first occurrence
73 | Console.WriteLine(s1.IndexOf("tig")); //2
74 | }
75 |
76 | static void RunStringFormat()
77 | {
78 | var users = new List
79 | {
80 | new { Username = "user1", Since = new DateTime(2022, 7, 7) , Followers = 15053 },
81 | new { Username = "user2", Since = new DateTime(2021, 5, 9) , Followers = 12046 },
82 | new { Username = "user3", Since = new DateTime(2022, 11, 10) , Followers = 14027 }
83 | };
84 |
85 | // Converts the value of objects to strings based on the
86 | // formats specified and inserts them into another string.
87 | var header = String.Format("{0,-12}{1,8}{2,12}\n",
88 | "Username", "Created At", "Followers");
89 |
90 | Console.WriteLine(header);
91 |
92 | foreach (var user in users)
93 | Console.WriteLine(String.Format("{0,-12}{1,8:yyyy}{2,12:N0}\n",
94 | user.Username, user.Since, user.Followers));
95 |
96 | }
97 |
98 | static void RunStringIsNullOrEmpty()
99 | {
100 | string s1 = "metigator";
101 | string s2 = "";
102 | string s3 = " ";
103 | string s4 = null;
104 | string s5 = String.Empty;
105 |
106 | // null or empty
107 | Console.WriteLine(String.IsNullOrEmpty(s1)); // false
108 |
109 | Console.WriteLine(String.IsNullOrEmpty(s2)); // true
110 |
111 | Console.WriteLine(String.IsNullOrEmpty(s3)); // false
112 |
113 | Console.WriteLine(String.IsNullOrEmpty(s4)); // true
114 |
115 | Console.WriteLine(String.IsNullOrEmpty(s5)); // true
116 | }
117 |
118 | static void RunStringIsNullOrWhiteSpace()
119 | {
120 | string s1 = "metigator";
121 | string s2 = "";
122 | string s3 = " ";
123 | string s4 = null;
124 | string s5 = String.Empty;
125 |
126 | // null or white spaces
127 | Console.WriteLine(String.IsNullOrWhiteSpace(s1)); // false
128 |
129 | Console.WriteLine(String.IsNullOrWhiteSpace(s2)); // true
130 |
131 | Console.WriteLine(String.IsNullOrWhiteSpace(s3)); // true
132 |
133 | Console.WriteLine(String.IsNullOrWhiteSpace(s4)); // true
134 |
135 | Console.WriteLine(String.IsNullOrWhiteSpace(s5)); // true
136 | }
137 |
138 | static void RunStringModify()
139 | {
140 | string s1 = "metior";
141 | string s2 = "metizanor";
142 | string s3 = "metixyzgator";
143 |
144 | //Returns a new string in which a specified string is inserted at a
145 | //specified index position in this instance.
146 | s1 = s1.Insert(4, "gat");
147 | Console.WriteLine(s1); // metigator
148 |
149 | // all occurrences the current string are replaced with
150 | // another specified Unicode character or String.
151 | s2 = s2.Replace("zan", "gat");
152 | Console.WriteLine(s2); // metigator
153 |
154 | //Returns a new string in which a specified number of characters
155 | //from the current string are deleted.
156 | s3 = s3.Remove(4, 3);
157 | Console.WriteLine(s3); // metigator
158 | }
159 |
160 | static void RunToCase()
161 | {
162 | string s1 = "Metigator";
163 |
164 | // Returns a copy of this string converted to uppercase
165 | // might produce culture specific output,
166 | // use it when user input string in their own language
167 | Console.WriteLine(s1.ToUpper());
168 |
169 | // Returns a copy of this string converted to lowercase.
170 | // might produce culture specific output,
171 | // use it when user input string in their own language
172 | Console.WriteLine(s1.ToLower());
173 |
174 | // Returns a copy of this string converted to lowercase.
175 | // use for non language specific data
176 | Console.WriteLine(s1.ToLowerInvariant());
177 |
178 | // Returns a copy of this string converted to uppercase.
179 | // use for non language specific data
180 | Console.WriteLine(s1.ToUpperInvariant());
181 | }
182 |
183 | static void RunTrim()
184 | {
185 | string s1 = " Metigator ";
186 | string s2 = "...Metigator....";
187 |
188 | //Removes all leading and trailing occurrences
189 | Console.WriteLine("Trim(), Trim(char)");
190 | Console.WriteLine(s1.Trim()); // "Metigator"
191 | Console.WriteLine(s2.Trim('.')); // "Metigator"
192 |
193 | //Removes all leading occurrences
194 | Console.WriteLine("TrimStart(), TrimStart(char)");
195 | Console.WriteLine(s1.TrimStart()); // "Metigator "
196 | Console.WriteLine(s2.TrimStart('.'));// "Metigator...."
197 |
198 | //Removes all trailing occurrences
199 | Console.WriteLine("TrimEnd(), TrimEnd(char)");
200 | Console.WriteLine(s1.TrimEnd());// " Metigator"
201 | Console.WriteLine(s2.TrimEnd('.')); // "...Metigator"
202 | }
203 |
204 | static void RunToCharacterArray()
205 | {
206 | string s1 = "metigator";
207 | char[] characters;
208 |
209 | //Copies the characters in this instance to a Unicode character array.
210 | characters = s1.ToCharArray();
211 |
212 | foreach (char ch in characters)
213 | Console.Write($" {ch}");
214 | }
215 |
216 | static void RunSplit()
217 | {
218 | string s1 = "This is metigator channel";
219 |
220 | // Returns a string array that contains the substrings
221 | // in this instance that are delimited by elements of
222 | // a specified string or Unicode character array.
223 | string[] words = s1.Split(" ");
224 |
225 | foreach (var word in words)
226 | Console.WriteLine(word);
227 | }
228 |
229 | static void RunStringJoin()
230 | {
231 | string[] values = { "Los Angeles", "1st Jan 1940", "15M" };
232 |
233 | //Concatenates the elements of a specified array or the members
234 | //of a collection, using the specified separator between each
235 | //element or member.
236 | string commaSeparated = string.Join(',', values);
237 |
238 | Console.WriteLine(commaSeparated); // Los Angeles,1st Jan 1940,15M
239 | }
240 |
241 |
242 | }
243 | }
--------------------------------------------------------------------------------
/Metigator44.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.3.32804.467
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L01.Ascii", "L01.Ascii\L01.Ascii.csproj", "{020E47EE-19B6-406B-8D64-91048B45E443}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L02.EncodingAndUnicode", "L02.EncodingAndUnicode\L02.EncodingAndUnicode.csproj", "{8B07B2D9-C2A6-4A36-BE20-27D2738C4BEB}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L03.Instantiation", "L03.Instantiation\L03.Instantiation.csproj", "{F7D48F69-AF50-4D22-9F97-CF82B89EF4E5}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L04.UnicodeAndStringComparison", "L04.L04.UnicodeAndStringComparison\L04.UnicodeAndStringComparison.csproj", "{FADDBA36-DD25-4401-92C6-19E9E03AE3E3}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L05.InternPool", "L05.InternPool\L05.InternPool.csproj", "{2CAF482A-E77F-4723-98F9-11B73A40DC66}"
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "L06.StringMethods", "L06.StringMethods\L06.StringMethods.csproj", "{A2E6A1AB-E188-48C3-AF99-FD60ADB09D97}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "L07.StringBuilderVsString", "L07.StringBuilderVsString\L07.StringBuilderVsString.csproj", "{446EE525-597B-4FE3-8593-86F262C312B9}"
19 | EndProject
20 | Global
21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 | Debug|Any CPU = Debug|Any CPU
23 | Release|Any CPU = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {020E47EE-19B6-406B-8D64-91048B45E443}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {020E47EE-19B6-406B-8D64-91048B45E443}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {020E47EE-19B6-406B-8D64-91048B45E443}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {020E47EE-19B6-406B-8D64-91048B45E443}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {8B07B2D9-C2A6-4A36-BE20-27D2738C4BEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {8B07B2D9-C2A6-4A36-BE20-27D2738C4BEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {8B07B2D9-C2A6-4A36-BE20-27D2738C4BEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {8B07B2D9-C2A6-4A36-BE20-27D2738C4BEB}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {F7D48F69-AF50-4D22-9F97-CF82B89EF4E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {F7D48F69-AF50-4D22-9F97-CF82B89EF4E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {F7D48F69-AF50-4D22-9F97-CF82B89EF4E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {F7D48F69-AF50-4D22-9F97-CF82B89EF4E5}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {FADDBA36-DD25-4401-92C6-19E9E03AE3E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {FADDBA36-DD25-4401-92C6-19E9E03AE3E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {FADDBA36-DD25-4401-92C6-19E9E03AE3E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {FADDBA36-DD25-4401-92C6-19E9E03AE3E3}.Release|Any CPU.Build.0 = Release|Any CPU
42 | {2CAF482A-E77F-4723-98F9-11B73A40DC66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43 | {2CAF482A-E77F-4723-98F9-11B73A40DC66}.Debug|Any CPU.Build.0 = Debug|Any CPU
44 | {2CAF482A-E77F-4723-98F9-11B73A40DC66}.Release|Any CPU.ActiveCfg = Release|Any CPU
45 | {2CAF482A-E77F-4723-98F9-11B73A40DC66}.Release|Any CPU.Build.0 = Release|Any CPU
46 | {A2E6A1AB-E188-48C3-AF99-FD60ADB09D97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {A2E6A1AB-E188-48C3-AF99-FD60ADB09D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {A2E6A1AB-E188-48C3-AF99-FD60ADB09D97}.Release|Any CPU.ActiveCfg = Release|Any CPU
49 | {A2E6A1AB-E188-48C3-AF99-FD60ADB09D97}.Release|Any CPU.Build.0 = Release|Any CPU
50 | {446EE525-597B-4FE3-8593-86F262C312B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51 | {446EE525-597B-4FE3-8593-86F262C312B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
52 | {446EE525-597B-4FE3-8593-86F262C312B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
53 | {446EE525-597B-4FE3-8593-86F262C312B9}.Release|Any CPU.Build.0 = Release|Any CPU
54 | EndGlobalSection
55 | GlobalSection(SolutionProperties) = preSolution
56 | HideSolutionNode = FALSE
57 | EndGlobalSection
58 | GlobalSection(ExtensibilityGlobals) = postSolution
59 | SolutionGuid = {7F1509DF-0621-4A2D-B8CC-16698B23B5F3}
60 | EndGlobalSection
61 | EndGlobal
62 |
--------------------------------------------------------------------------------