<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>.net | MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Fri, 17 Apr 2020 18:23:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>.net | MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>Create an Excel file in C# without Microsoft Office or Third party plugins</title>
		<link>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/</link>
					<comments>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sat, 18 Apr 2020 18:07:00 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.net-framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[epplus5]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel-cell]]></category>
		<category><![CDATA[excel-document]]></category>
		<category><![CDATA[excel-row]]></category>
		<category><![CDATA[excel-sheet]]></category>
		<category><![CDATA[excel-workbook]]></category>
		<category><![CDATA[excellibrary]]></category>
		<category><![CDATA[free-dll]]></category>
		<category><![CDATA[free-library]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[libre-office]]></category>
		<category><![CDATA[microsoft-excel]]></category>
		<category><![CDATA[microsoft-office]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[workbook]]></category>
		<category><![CDATA[xls]]></category>
		<category><![CDATA[xlsx]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=247</guid>

					<description><![CDATA[<p>How to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed</p>
<p>The post <a href="https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/">Create an Excel file in C# without Microsoft Office or Third party plugins</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>What I&#8217;m about to say seems paradoxical, but the reality is that in open environments (as in PHP for example) it is often easier and we have less problems in creating or converting files in proprietary systems, compared to what happens on frameworks such as Microsoft&#8217;s .Net; this is the case when we have to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed, without the right libraries in our project we will have several headaches. A quick solution is to use the open-source library <a href="https://github.com/gustafl/ExcelLibrary" class="aioseop-link">ExcelLibrary</a>. This looks to be a port of the PHP ExcelWriter, it&#8217;s very simple, small and easy to use.</p>



<p><strong>Using ExcelLibrary</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-csharp&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;C#&quot;,&quot;modeName&quot;:&quot;csharp&quot;}">Workbook workbook = new Workbook();
workbook.Open(&quot;Book1.xlsx&quot;);
Sheet sheet = workbook.Sheet(&quot;Sheet1&quot;);
Row row = sheet.Row(2);
Cell cell = row.Cell(3);
string text = cell.Value;</pre></div>



<p><strong>Main features</strong></p>



<ul><li>No dependencies except .NET Framework 4.5. Easy to include in other solutions.</li><li>Built and extendable with LINQ. Most collections in the library (e.g. <code>Workbook.Sheets</code> or <code>Row.Cells</code>) is of type <code>IEnumerable&lt;T&gt;</code>, which allows you to use LINQ queries to find exactly what you need.</li><li>Respects the visibility of sheets, rows and columns. Set the <code>IncludeHidden</code> option to <code>true</code>to return hidden objects.</li><li>Well-tested. The library is being developed using principles of Test-driven development (TDD). A large set of unit tests verifies that new bugs are not introduced on code changes.</li><li>Well-documented. A software library is only as useful as its documentation.</li></ul>



<p>Another valid alternative is <a href="https://github.com/EPPlusSoftware/EPPlus" class="aioseop-link">EPPLUS5</a>  however it has a new license model from version 5, it&#8217;s still free to use in some cases, but will require a commercial license to be used in a commercial business.</p><p>The post <a href="https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/">Create an Excel file in C# without Microsoft Office or Third party plugins</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">247</post-id>	</item>
		<item>
		<title>Base64 encoding / decoding functions in VbScript / Classic ASP</title>
		<link>https://www.maxvergelli.com/base64-encoding-decoding-functions-in-vbscript-classic-asp/</link>
					<comments>https://www.maxvergelli.com/base64-encoding-decoding-functions-in-vbscript-classic-asp/#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 06 Mar 2020 13:43:10 +0000</pubDate>
				<category><![CDATA[Classic ASP]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[classic-asp]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[decoding]]></category>
		<category><![CDATA[decryption]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string-conversion]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vbscript]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=122</guid>

					<description><![CDATA[<p>With the following functions Base64Encode(sText) and Base64Decode(ByVal vCode), You can easly encode/decode a text in/from base64 in VBScript/Classic ASP:</p>
<p>The post <a href="https://www.maxvergelli.com/base64-encoding-decoding-functions-in-vbscript-classic-asp/">Base64 encoding / decoding functions in VbScript / Classic ASP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><span id="result_box" class="" lang="en">With the following functions <em>Base64Encode(sText)</em> and <em>Base64Decode(ByVal vCode)</em>, You can easly encode/decode a text in/from base64 in VBScript/Classic ASP:</span></p>


<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vbscript&quot;,&quot;mime&quot;:&quot;text/vbscript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;VBScript&quot;,&quot;modeName&quot;:&quot;vb&quot;}">Function Base64Encode(sText)
  Dim oXML, oNode
  Set oXML = CreateObject(&quot;Msxml2.DOMDocument.3.0&quot;)
  Set oNode = oXML.CreateElement(&quot;base64&quot;)
  oNode.dataType = &quot;bin.base64&quot;
  oNode.nodeTypedValue = Stream_StringToBinary(sText)
  Base64Encode = oNode.text
  Set oNode = Nothing
  Set oXML = Nothing
End Function

Function Base64Decode(ByVal vCode)
  Dim oXML, oNode
  Set oXML = CreateObject(&quot;Msxml2.DOMDocument.3.0&quot;)
  Set oNode = oXML.CreateElement(&quot;base64&quot;)
  oNode.dataType = &quot;bin.base64&quot;
  oNode.text = vCode
  Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
  Set oNode = Nothing
  Set oXML = Nothing
End Function

Private Function Stream_StringToBinary(Text)
  Const adTypeText = 2
  Const adTypeBinary = 1
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject(&quot;ADODB.Stream&quot;)
  BinaryStream.Type = adTypeText
  BinaryStream.CharSet = &quot;us-ascii&quot;
  BinaryStream.Open
  BinaryStream.WriteText Text
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeBinary
  BinaryStream.Position = 0
  Stream_StringToBinary = BinaryStream.Read
  Set BinaryStream = Nothing
End Function

Private Function Stream_BinaryToString(Binary)
  Const adTypeText = 2
  Const adTypeBinary = 1
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject(&quot;ADODB.Stream&quot;)
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.Write Binary
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeText
  BinaryStream.CharSet = &quot;us-ascii&quot;
  Stream_BinaryToString = BinaryStream.ReadText
  Set BinaryStream = Nothing
End Function</pre></div>



<p></p><p>The post <a href="https://www.maxvergelli.com/base64-encoding-decoding-functions-in-vbscript-classic-asp/">Base64 encoding / decoding functions in VbScript / Classic ASP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/base64-encoding-decoding-functions-in-vbscript-classic-asp/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">122</post-id>	</item>
		<item>
		<title>vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) &#8211; .Dispose() Method common problem</title>
		<link>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/</link>
					<comments>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 14 Jan 2020 15:47:04 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dispose]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=74</guid>

					<description><![CDATA[<p>Many people are in trouble and on forums asking why the .Net Bitmap object does not release an image with its .Dispose() method. The Bitmap object (after its destruction too) seems to lock the image file, then we are not &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/" aria-label="vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) &#8211; .Dispose() Method common problem">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/">vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) – .Dispose() Method common problem</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Many people are in trouble and on forums asking why the .Net Bitmap object does not release an image with its .Dispose() method. The Bitmap object (after its destruction too) seems to lock the image file, then we are not able to move or delete that image file through the file system.</p>
<p>This is a known problem and it occurs when we declare and instantiate a Bitmap object and destruct that like in the following code:</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>                &#8216;create a bitmap object<br />
                Dim myBitmap As New Bitmap(&quot;c:myimage.jpg&quot;)</p>
<p>                &#8216;editing image routines, right here<br />
                &#8216;&#8230;</p>
<p>                &#8216;release all Bitmap object resources<br />
                myBitmap.Dispose()</p>
<p>[/sourcecode]</p>
<p>The above code it is formally correct, however in same circumstances the .net garbage collector cannot recognize bitmap&#8217;s disposing; Dispose() method leaves the image file in an unusable state, then as <a href="http://msdn.microsoft.com/en-us/library/8th8381z.aspx">MSDN</a> said, we MUST release explicitly any reference after a Dispose() call;</p>
<p>with the following code, You will not encounter any problem, and after Dispose() You can edit, move, delete the image file by the filesystem functions&#8230;</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
                &#8216;create a bitmap object<br />
                Dim myBitmap As New Bitmap(&quot;c:myimage.jpg&quot;)</p>
<p>                &#8216;editing image routines, right here<br />
                &#8216;&#8230;</p>
<p>                &#8216;release image reference<br />
                While myBitmap IsNot Nothing<br />
                    myBitmap.Dispose()<br />
                    myBitmap = Nothing  &#8216;&lt;&#8211; tells .net garbage collector to release resources<br />
                End While</p>
<p>[/sourcecode]</p>
<p>Happy image editing! 🙂</p><p>The post <a href="https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/">vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) – .Dispose() Method common problem</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">74</post-id>	</item>
		<item>
		<title>How to remove accent marks and german umlauts from URLs and Strings in .NET</title>
		<link>https://www.maxvergelli.com/how-to-remove-accent-marks-and-german-umlauts-from-urls-and-strings-in-vb-net-c-sharp/</link>
					<comments>https://www.maxvergelli.com/how-to-remove-accent-marks-and-german-umlauts-from-urls-and-strings-in-vb-net-c-sharp/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 06 Sep 2019 14:40:50 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[String Manipulation Algorithms]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[char]]></category>
		<category><![CDATA[char-conversion]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[intellisense]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String-class]]></category>
		<category><![CDATA[string-conversion]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=51</guid>

					<description><![CDATA[<p>I wrote two functions in .NET to remove easly any accent and umlaut marks from a string and to get the equivalent non-accented string, this is very useful to normalize URLs; for example, with the StripAccentMarks() method, from &#8220;àbcdèéfghìlmnòpqrstùvzäöüÄÖÜ&#8221; u&#8217;ll &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-remove-accent-marks-and-german-umlauts-from-urls-and-strings-in-vb-net-c-sharp/" aria-label="How to remove accent marks and german umlauts from URLs and Strings in .NET">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/how-to-remove-accent-marks-and-german-umlauts-from-urls-and-strings-in-vb-net-c-sharp/">How to remove accent marks and german umlauts from URLs and Strings in .NET</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I wrote two functions in .NET to remove easly any accent and umlaut marks from a string and to get the equivalent non-accented string, this is very useful to normalize URLs; for example, with the <em>StripAccentMarks()</em> method, from &#8220;àbcdèéfghìlmnòpqrstùvzäöüÄÖÜ&#8221; u&#8217;ll get &#8220;abcdeefghilmnopqrstuvzaouAOU&#8221;;</p>
<p>besides, if u&#8217;ll need to convert each german umlaut to the corresponding two-letter chars, u can also use the <em>ReplaceGermanUmlauts()</em> method&#8230;</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
Public Shared Function StripAccentMarks(ByVal input_string As String) As String<br />
   Dim n_s As String = input_string.Normalize(NormalizationForm.FormD)<br />
   Dim s As New StringBuilder()<br />
   Dim c As Char<br />
   For i As Integer = 0 To n_s.Length &#8211; 1<br />
      c = n_s(i)<br />
      If System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) &lt;&gt; System.Globalization.UnicodeCategory.NonSpacingMark Then<br />
         s.Append(c)<br />
      End If<br />
   Next<br />
   Return s.ToString<br />
End Function<br />
[/sourcecode]<br />
[sourcecode language=&#8221;vb&#8221;]<br />
Public Shared Function ReplaceGermanUmlauts(ByVal input_string As String) As String<br />
   Dim s As String = input_string&lt;/pre&gt;<br />
s = s.Replace(&quot;ä&quot;, &quot;ae&quot;)<br />
 s = s.Replace(&quot;ö&quot;, &quot;oe&quot;)<br />
 s = s.Replace(&quot;ü&quot;, &quot;ue&quot;)<br />
 s = s.Replace(&quot;Ä&quot;, &quot;Ae&quot;)<br />
 s = s.Replace(&quot;Ö&quot;, &quot;Oe&quot;)<br />
 s = s.Replace(&quot;Ü&quot;, &quot;Ue&quot;)<br />
 s = s.Replace(&quot;ß&quot;, &quot;ss&quot;)<br />
 Return s<br />
End Function<br />
[/sourcecode]</p>
<p>Have a nice day!</p>
<p>Max 😀</p><p>The post <a href="https://www.maxvergelli.com/how-to-remove-accent-marks-and-german-umlauts-from-urls-and-strings-in-vb-net-c-sharp/">How to remove accent marks and german umlauts from URLs and Strings in .NET</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-remove-accent-marks-and-german-umlauts-from-urls-and-strings-in-vb-net-c-sharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">51</post-id>	</item>
		<item>
		<title>Multilingual applications with VB.NET</title>
		<link>https://www.maxvergelli.com/developing-multilingual-applications-with-vb-net-c-sharp/</link>
					<comments>https://www.maxvergelli.com/developing-multilingual-applications-with-vb-net-c-sharp/#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 09 Aug 2019 14:36:19 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[compiling]]></category>
		<category><![CDATA[culture-codename]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[intellisense]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[multi-language]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[resx]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String-class]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[visual-studio]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=49</guid>

					<description><![CDATA[<p>In this simple tutorial you&#8217;ll learn how to manage different languages for a vb.NET application and the simplest way to access programmatically to the string values in the resource compiled files (*.resx) created by Visual Studio; Adding resource files: First &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/developing-multilingual-applications-with-vb-net-c-sharp/" aria-label="Multilingual applications with VB.NET">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/developing-multilingual-applications-with-vb-net-c-sharp/">Multilingual applications with VB.NET</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In this simple tutorial you&#8217;ll learn how to manage different languages for a vb.NET application and the simplest way to access programmatically to the string values in the resource compiled files (*.resx) created by Visual Studio;</p>
<p><strong>Adding resource files:</strong></p>
<p>First of all, add a folder named &#8220;resources/&#8221; in your project.</p>
<p>Inside this folder, right click then from the context menu choose &#8220;add an element&#8221; -> &#8220;new element&#8221; -> select &#8220;Resource File (resx)&#8221; -> create a file named &#8220;Resources.en-US.resx&#8221;</p>
<p>In the &#8220;Resources.en-US.resx&#8221; file, You have to write all the strings used by your application.<br />
It&#8217;s important that your language resource file is named as &#8220;Resources.{Language Code Name}.resx&#8221;, so VS can reach automatically this file.</p>
<p>The rsx file is just a list of Key-Value items, then You have to give a key-name for each string value; don&#8217;t use spaces in key-names, otherwise it&#8217;s best using &#8220;_&#8221; symbol.</p>
<p>Insert only two test lines in your new rsx file as the following&#8230;</p>
<p>KEY &#8211; VALUE:<br />
<code><br />
TEST_STRING1	us1<br />
TEST_STRING2	us2<br />
</code></p>
<p>Then, compile your project and if it&#8217;s all right, You will find a new folder in &#8220;binRelease&#8221; named &#8220;en-US&#8221; created by VS, with a file &#8220;{your project name}.resources.dll&#8221;; this file contains all the strings for the english-US language (&#8220;en-US&#8221;) and right now You can access them programmatically.</p>
<p>If You want add a new language to your application, just copy the rsx file and rename it in &#8220;Resources.{Language Code Name}.resx&#8221; where the language code name is one of those listed at <a href="http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx" title="http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx" target="_blank" rel="noopener noreferrer">http://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx</a>.</p>
<p><strong>Step 2, how to programmatically select the language and strings:</strong></p>
<p>Add a vb class &#8220;Resources.vb&#8221; in the &#8220;resources&#8221; folder with the following code</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
Public Class Resources</p>
<p>    Public Shared Function GetValue(ByVal name As ResourceName) As String<br />
        Return My.Resources.ResourceManager.GetObject(name.ToString)<br />
    End Function</p>
<p>    Public Shared Property Language() As CultureCodeName<br />
        Get<br />
            Dim c As CultureCodeName = Nothing<br />
            Dim cs As String = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString().Replace(New Char() {&quot;-&quot;c}, New Char() {&quot;_&quot;c})<br />
            For Each cc As CultureCodeName In [Enum].GetValues(GetType(CultureCodeName))<br />
                If cs = cc.ToString Then<br />
                    c = cc<br />
                    Exit For<br />
                End If<br />
            Next<br />
            Return c<br />
        End Get<br />
        Set(ByVal cultureCodeName As CultureCodeName)<br />
            Dim c As String = cultureCodeName.ToString.Replace(New Char() {&quot;_&quot;c}, New Char() {&quot;-&quot;c})<br />
            System.Threading.Thread.CurrentThread.CurrentUICulture = _<br />
                            System.Globalization.CultureInfo.GetCultureInfo(c)<br />
        End Set<br />
    End Property</p>
<p>End Class<br />
[/sourcecode]</p>
<p>then, add a vb &#8220;code file&#8221; named &#8220;CultureCodeNames.vb&#8221; in &#8220;resources&#8221; folder with the following code</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>Public Enum CultureCodeName</p>
<p>    en_US<br />
    &#8216;if You want add a new language, after creating the rsx file,<br />
    &#8216;also add here the code name, with &quot;-&quot; replaced in &quot;_&quot;</p>
<p>End Enum</p>
<p>[/sourcecode]</p>
<p>Finally, add the last vb codefile &#8220;ResourceNames.vb&#8221; in &#8220;resources&#8221; folder with this code</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>Public Enum ResourceName</p>
<p>    &#8216;add here all the key names in the RSX file<br />
    TEST_STRING1<br />
    TEST_STRING2</p>
<p>End Enum</p>
<p>[/sourcecode]</p>
<p>The configuration is finished.<br />
In your project, add a button to a form, then add the following vb code in the <em>codebehind</em> to learn how to access to different language RSX files and their strings inside.</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click</p>
<p>        &#8216;Select a language for your app<br />
        Resources.Language = CultureCodeName.en_US</p>
<p>        &#8216;show test string 1<br />
        MessageBox.Show(Resources.GetValue(ResourceName.TEST_STRING1))</p>
<p>        &#8216;show test string 2<br />
        MessageBox.Show(Resources.GetValue(ResourceName.TEST_STRING2))</p>
<p>        &#8216;show the current language code<br />
        MessageBox.Show(Resources.Language.ToString)</p>
<p>    End Sub<br />
[/sourcecode]</p>
<p>It&#8217;s very useful because when you will be writing the code, VS automatically suggests the strings that you can use, saving a lot of time and by selecting a language with &#8220;Resources.Language&#8221;, You can translate your application strings on the fly. </p>
<p>Have a nice day!</p>
<p>Max</p><p>The post <a href="https://www.maxvergelli.com/developing-multilingual-applications-with-vb-net-c-sharp/">Multilingual applications with VB.NET</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/developing-multilingual-applications-with-vb-net-c-sharp/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">49</post-id>	</item>
		<item>
		<title>MySqlHelper VB.NET class &#8211; easly execute commands against a MySQL database</title>
		<link>https://www.maxvergelli.com/mysqlhelper-vb-net-class-execute-commands-against-a-mysql-database/</link>
					<comments>https://www.maxvergelli.com/mysqlhelper-vb-net-class-execute-commands-against-a-mysql-database/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Wed, 01 Jun 2016 14:28:05 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[connection-string]]></category>
		<category><![CDATA[connector-net]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[data-adapter]]></category>
		<category><![CDATA[data-layer]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database-connector]]></category>
		<category><![CDATA[dataset]]></category>
		<category><![CDATA[datetime-conversion]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[execute-scalar]]></category>
		<category><![CDATA[execute-sql-programmatically]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql-client]]></category>
		<category><![CDATA[mysql-command]]></category>
		<category><![CDATA[mysql-database-connector]]></category>
		<category><![CDATA[mysql-datetime]]></category>
		<category><![CDATA[mysql-datetime-conversion]]></category>
		<category><![CDATA[mysql-parameter]]></category>
		<category><![CDATA[record]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql-command]]></category>
		<category><![CDATA[sql-reader]]></category>
		<category><![CDATA[stored-procedure]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=45</guid>

					<description><![CDATA[<p>Hi all, with the following free .net helper class you can easly execute SQL commands against a MySQL database, execute stored procedures, get or programmatically update tables/DataSet objects and convert to and from MySQL datetime types. Enjoy! 🙂 [sourcecode language=&#8221;vb&#8221;] &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/mysqlhelper-vb-net-class-execute-commands-against-a-mysql-database/" aria-label="MySqlHelper VB.NET class &#8211; easly execute commands against a MySQL database">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/mysqlhelper-vb-net-class-execute-commands-against-a-mysql-database/">MySqlHelper VB.NET class – easly execute commands against a MySQL database</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hi all, with the following free .net helper class you can easly execute SQL commands against a MySQL database, execute stored procedures, get or programmatically update tables/DataSet objects and convert to and from MySQL datetime types.</p>
<p>Enjoy! 🙂</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>&#8216;	MySqlHelper VB.NET class<br />
&#8216;	http://www.maxvergelli.com/</p>
<p>&#8216;	Copyright (c) 2016 Max Vergelli</p>
<p>&#8216;   Vers. 2.1.0<br />
&#8216;   Date: 21/03/2016</p>
<p>&#8216;   Description:<br />
&#8216;   .NET helper class to easly execute SQL commands against a MySQL database,<br />
&#8216;   execute stored procedures, get or programmatically update DataSet objects,<br />
&#8216;   and convert to and from MySQL datetime types.<br />
&#8216;<br />
&#8216;   Before use this class, You have to install and import in your project the<br />
&#8216;   last MySQL Connector/NET at<br />
&#8216;   http://dev.mysql.com/doc/refman/5.0/es/connector-net.html</p>
<p>&#8216;	Permission is hereby granted, free of charge, to any person obtaining a copy<br />
&#8216;	of this software and associated documentation files (the &quot;Software&quot;), to deal<br />
&#8216;	in the Software without restriction, including without limitation the rights<br />
&#8216;	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
&#8216;	copies of the Software, and to permit persons to whom the Software is<br />
&#8216;	furnished to do so, subject to the following conditions:</p>
<p>&#8216;	The above copyright notice and this permission notice shall be included in<br />
&#8216;	all copies or substantial portions of the Software.</p>
<p>&#8216;	THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
&#8216;	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
&#8216;	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
&#8216;	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
&#8216;	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
&#8216;	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
&#8216;	THE SOFTWARE.</p>
<p>Imports System.Data<br />
Imports System.Globalization<br />
Imports MySql.Data.MySqlClient</p>
<p>Public Class MySqlHelper</p>
<p>    Private _cnx_string As String = Nothing<br />
    Private _cnx_obj As MySqlConnection = Nothing</p>
<p>    Private Function IsConnectionAlive() As Boolean<br />
        Dim is_alive As Boolean = False<br />
        If _cnx_obj IsNot Nothing AndAlso _cnx_obj.State &lt;&gt; ConnectionState.Closed Then<br />
            is_alive = True<br />
        End If<br />
        Return is_alive<br />
    End Function</p>
<p>    Private Sub CloseConnection()</p>
<p>        Try</p>
<p>            If IsConnectionAlive() Then<br />
                _cnx_obj.Close()<br />
            End If<br />
            _cnx_obj = Nothing</p>
<p>        Catch ex As Exception</p>
<p>            _cnx_obj = Nothing</p>
<p>        End Try</p>
<p>    End Sub</p>
<p>    Public ReadOnly Property ConnectionString() As String<br />
        Get<br />
            Return _cnx_string<br />
        End Get<br />
    End Property</p>
<p>    Public Function IsOpen() As Boolean<br />
        Return IsConnectionAlive()<br />
    End Function</p>
<p>    Public Sub New(Optional ByVal db_connection_string As String = &quot;&quot;, _<br />
                   Optional ByVal open_connection As Boolean = False)</p>
<p>        _cnx_string = db_connection_string</p>
<p>        If _cnx_string.Length &gt; 0 And open_connection = True Then</p>
<p>            Dim is_open As Boolean = Open(_cnx_string)</p>
<p>        End If</p>
<p>    End Sub</p>
<p>    Public Function Open(ByVal db_connection_string As String) As Boolean</p>
<p>        Dim success As Boolean = False<br />
        Try</p>
<p>            If IsConnectionAlive() = False Then</p>
<p>                If db_connection_string.Length &gt; 0 AndAlso _cnx_obj Is Nothing Then</p>
<p>                    _cnx_string = db_connection_string<br />
                    _cnx_obj = New MySqlConnection<br />
                    _cnx_obj.ConnectionString = _cnx_string<br />
                    _cnx_obj.Open()<br />
                    success = True</p>
<p>                End If</p>
<p>            End If</p>
<p>        Catch ex As Exception</p>
<p>            CloseConnection()<br />
            success = False</p>
<p>        End Try<br />
        Return success</p>
<p>    End Function</p>
<p>    Public Sub Close()</p>
<p>        CloseConnection()</p>
<p>    End Sub</p>
<p>    Protected Overrides Sub Finalize()<br />
        CloseConnection()<br />
    End Sub</p>
<p>    &#8216;get a DataRow object with the first row of a SQL select command<br />
    Public Function SelectFirstRow(ByVal sql_select As String) As DataRow</p>
<p>        Dim ds As DataSet = SelectRows(sql_select)<br />
        If ds Is Nothing Then<br />
            Return Nothing<br />
        End If<br />
        If ds.Tables.Count &lt; 1 Then<br />
            Return Nothing<br />
        End If<br />
        If ds.Tables(0).Rows.Count &lt; 1 Then<br />
            Return Nothing<br />
        End If<br />
        Return ds.Tables(0).Rows(0)</p>
<p>    End Function</p>
<p>    &#8216;get a DataSet object with the rows of a SQL select command<br />
    Public Function SelectRows(ByVal sql_select As String) As DataSet</p>
<p>        Dim ds As DataSet = Nothing<br />
        Try</p>
<p>            If IsConnectionAlive() Then</p>
<p>                Dim cmd As MySqlCommand = New MySqlCommand(sql_select, _cnx_obj)</p>
<p>                Dim da As MySqlDataAdapter = New MySqlDataAdapter<br />
                da.SelectCommand = cmd</p>
<p>                ds = New DataSet<br />
                da.Fill(ds)</p>
<p>                da = Nothing</p>
<p>            End If</p>
<p>        Catch ex As Exception</p>
<p>            ds = Nothing</p>
<p>        End Try<br />
        Return ds</p>
<p>    End Function</p>
<p>    &#8216;Execute a MySql Stored Procedure<br />
    Public Overloads Function ExecuteStoredProcedure(ByVal stored_procedure_name As String) As DataSet</p>
<p>        Return ExecuteProcedure(stored_procedure_name)</p>
<p>    End Function</p>
<p>    &#8216;Execute a MySql Stored Procedure with parameters</p>
<p>    &#8216;How to create the parameters<br />
    &#8216;Dim param As MySqlParameter = New MySqlParameter(&quot;?v_id&quot;, MySqlDbType.Int32)<br />
    &#8216;param.Value = 1<br />
    &#8216;param.Direction = ParameterDirection.Input</p>
<p>    Public Overloads Function ExecuteStoredProcedure(ByVal stored_procedure_name As String, _<br />
                                                     ByVal ParamArray parameters As MySqlParameter()) As DataSet</p>
<p>        Return ExecuteProcedure(stored_procedure_name, parameters)</p>
<p>    End Function</p>
<p>    Private Function ExecuteProcedure(ByVal procedure_name As String, _<br />
                                            ByVal ParamArray sql_parameters As MySqlParameter()) As DataSet</p>
<p>        Dim ds As DataSet = Nothing<br />
        Try<br />
            If IsConnectionAlive() Then</p>
<p>                Dim cmd As New MySqlCommand(procedure_name, _cnx_obj)</p>
<p>                cmd.CommandType = CommandType.StoredProcedure</p>
<p>                If sql_parameters IsNot Nothing Then<br />
                    For Each p As MySqlParameter In sql_parameters<br />
                        cmd.Parameters.Add(p)<br />
                    Next<br />
                End If</p>
<p>                Dim da As MySqlDataAdapter = New MySqlDataAdapter<br />
                da.SelectCommand = cmd<br />
                ds = New DataSet<br />
                da.Fill(ds)<br />
                da = Nothing</p>
<p>                cmd.Parameters.Clear()</p>
<p>            End If<br />
        Catch ex As Exception</p>
<p>            ds = Nothing</p>
<p>        End Try</p>
<p>        Return ds</p>
<p>    End Function</p>
<p>    &#8216;UpdateRows() function automatically generates single-table commands used to reconcile changes made to a DataSet<br />
    &#8216;with the associated table in the MySQL database.<br />
    &#8216;The function gets<br />
    &#8216; &#8211; the SQL SELECT used to populate the dataset<br />
    &#8216; &#8211; the updated dataset<br />
    &#8216; &#8211; the table name that must be updated in the database<br />
    &#8216;Note:<br />
    &#8216;The SQL SELECT must also return at least one primary key or unique column, otherwise an exception is generated;</p>
<p>    Public Function UpdateRows(ByVal sql_select As String, ByRef input_dataset As DataSet, ByVal table_name As String) As Boolean</p>
<p>        Dim success As Boolean = False<br />
        Try</p>
<p>            If IsConnectionAlive() Then</p>
<p>                Dim data_adapter As New MySqlDataAdapter(sql_select, _cnx_obj)<br />
                Dim cmd_builder As New MySqlCommandBuilder(data_adapter)<br />
                data_adapter.Update(input_dataset, table_name)<br />
                success = True</p>
<p>            End If</p>
<p>        Catch ex As Exception</p>
<p>            success = False</p>
<p>        End Try</p>
<p>        Return success</p>
<p>    End Function</p>
<p>    &#8216;To use a MySqlDataReader,<br />
    &#8216;You have to use OpenReader() and CloseReader() functions like in the following example:<br />
    &#8216;<br />
    &#8216;    Public Sub ReadMyData(ByVal connection_string As String)<br />
    &#8216;<br />
    &#8216;        Dim mysql As MySqlHelper = New MySqlHelper()<br />
    &#8216;        mysql.Open(connection_string)<br />
    &#8216;<br />
    &#8216;        Dim sql As String = &quot;SELECT OrderID, CustomerID FROM Orders&quot;<br />
    &#8216;        Dim reader As MySqlDataReader = Nothing<br />
    &#8216;<br />
    &#8216;        mysql.OpenReader(reader, sql)<br />
    &#8216;        While reader.Read()<br />
    &#8216;            Console.WriteLine((reader.GetInt32(0) &amp; &quot;, &quot; &amp; reader.GetString(1)))<br />
    &#8216;        End While<br />
    &#8216;        mysql.CloseReader(reader)<br />
    &#8216;<br />
    &#8216;        mysql.Close()<br />
    &#8216;<br />
    &#8216;    End Sub</p>
<p>    Public Sub OpenReader(ByRef reader As MySqlDataReader, ByVal sql_select As String)</p>
<p>        Try<br />
            If IsConnectionAlive() Then</p>
<p>                Dim cmd As New MySqlCommand(sql_select, _cnx_obj)<br />
                reader = cmd.ExecuteReader()</p>
<p>            End If</p>
<p>        Catch ex As Exception</p>
<p>            reader = Nothing</p>
<p>        End Try</p>
<p>    End Sub</p>
<p>    Public Sub CloseReader(ByRef reader As MySqlDataReader)</p>
<p>        Try</p>
<p>            reader.Close()</p>
<p>        Catch ex As Exception</p>
<p>        End Try</p>
<p>    End Sub</p>
<p>    &#8216;Execute SQL command and return the number of records affected<br />
    Public Function Execute(ByVal sql_command As String) As Long</p>
<p>        Dim affected_rows As Long = 0</p>
<p>        Try<br />
            If IsConnectionAlive() Then</p>
<p>                Dim cmd As New MySqlCommand(sql_command, _cnx_obj)</p>
<p>                affected_rows = cmd.ExecuteNonQuery()</p>
<p>            End If</p>
<p>        Catch ex As Exception</p>
<p>            affected_rows = 0</p>
<p>        End Try</p>
<p>        Return affected_rows</p>
<p>    End Function</p>
<p>    &#8216;GetSingleValue() function executes the query, and returns the value of the first column of the first row in the<br />
    &#8216;result set returned by the query. Extra columns or rows are ignored.<br />
    &#8216;Note:<br />
    &#8216;Use the GetSingleValue() method to retrieve a single value (for example, an aggregate value)<br />
    &#8216;from a database, like &quot;select count(*) from region&quot;</p>
<p>    Public Overloads Function GetSingleValue(ByVal sql_select As String) As Object</p>
<p>        Return ExecuteScalar(sql_select, DirectCast(Nothing, MySqlParameter()))</p>
<p>    End Function</p>
<p>    Public Overloads Function GetSingleValue(ByVal sql_select As String, ByVal ParamArray sql_parameters As MySqlParameter()) As Object</p>
<p>        Return ExecuteScalar(sql_select, sql_parameters)</p>
<p>    End Function</p>
<p>    &#8216;ExecuteScalar: Executes the query, and returns the value (integer/string) of the first column of the first row in the result set returned by the query. Extra columns or rows are ignored.<br />
    Private Function ExecuteScalar(ByVal sql_select As String, ByVal ParamArray sql_parameters As MySqlParameter()) As Object</p>
<p>        Dim row As Object = Nothing<br />
        Try<br />
            If IsConnectionAlive() Then</p>
<p>                Dim cmd As New MySqlCommand(sql_select, _cnx_obj)<br />
                If sql_parameters IsNot Nothing Then<br />
                    For Each p As MySqlParameter In sql_parameters<br />
                        cmd.Parameters.Add(p)<br />
                    Next<br />
                End If<br />
                row = cmd.ExecuteScalar()<br />
                cmd.Parameters.Clear()</p>
<p>            End If<br />
        Catch ex As Exception</p>
<p>            row = Nothing</p>
<p>        End Try</p>
<p>        Return row</p>
<p>    End Function</p>
<p>    &#8217;25/1/12 -&gt; 2012-01-25<br />
    Public Overloads Function ConvertToMySqlDate(ByVal input_date As Date) As String</p>
<p>        Return input_date.ToString(&quot;yyyy-MM-dd&quot;)</p>
<p>    End Function</p>
<p>    &#8217;25/1/12 -&gt; 2012-01-25<br />
    Public Overloads Function ConvertToMySqlDate(ByVal input_date As String) As String</p>
<p>        Return ConvertDateTime(input_date, DATETIME_TYPE.MYSQL, True)</p>
<p>    End Function</p>
<p>    &#8217;25/1/12 13:00 -&gt; 2012-01-25 13:00:00<br />
    Public Overloads Function ConvertToMySqlDateTime(ByVal input_datetime As DateTime) As String</p>
<p>        Return input_datetime.ToString(&quot;yyyy-MM-dd HH:mm:ss&quot;)</p>
<p>    End Function</p>
<p>    &#8217;25/1/12 13:00 -&gt; 2012-01-25 13:00:00<br />
    Public Overloads Function ConvertToMySqlDateTime(ByVal input_datetime As String) As String</p>
<p>        Return ConvertDateTime(input_datetime, DATETIME_TYPE.MYSQL)</p>
<p>    End Function</p>
<p>    &#8216;2012-01-25 -&gt; 25-01-2012<br />
    Public Overloads Function ConvertToDate(ByVal mysql_date As Date) As String</p>
<p>        Return mysql_date.ToString(&quot;dd-MM-yyyy&quot;)</p>
<p>    End Function</p>
<p>    &#8216;2012-01-25 -&gt; 25-01-2012<br />
    Public Overloads Function ConvertToDate(ByVal mysql_date As String) As String</p>
<p>        Return ConvertDateTime(mysql_date, DATETIME_TYPE.SYSTEM, True)</p>
<p>    End Function</p>
<p>    &#8216;2012-01-25 13:00:00 -&gt; 25-01-2012 13:00:00<br />
    Public Overloads Function ConvertToDateTime(ByVal mysql_datetime As DateTime) As String</p>
<p>        Return mysql_datetime.ToString(&quot;dd-MM-yyyy HH:mm:ss&quot;)</p>
<p>    End Function</p>
<p>    &#8216;2012-01-25 13:00:00 -&gt; 25-01-2012 13:00:00<br />
    Public Overloads Function ConvertToDateTime(ByVal mysql_datetime As String) As String</p>
<p>        Return ConvertDateTime(mysql_datetime, DATETIME_TYPE.SYSTEM)</p>
<p>    End Function</p>
<p>    Private Enum DATETIME_TYPE As Integer<br />
        SYSTEM = 0<br />
        MYSQL = 1<br />
    End Enum</p>
<p>    Private Function ConvertDateTime(ByVal input_datetime As String, ByVal output_datetime_type As DATETIME_TYPE, _<br />
                                                                    Optional ByVal get_only_date As Boolean = False) As String</p>
<p>        &#8216;The function returns a datetime in a well-formatted string for regular or MySQL use.<br />
        &#8216;You have to insert a datetime string formatted by {,/,-,.,:} symbols.<br />
        &#8216;Besides, for the input date, You need to specify &quot;day, month and year&quot;;<br />
        &#8216;for the time, only &quot;hour and minutes&quot;, &quot;seconds&quot; doesn&#8217;t matter.</p>
<p>        &#8216;The function returns Nothing if an error is encountered.</p>
<p>        &#8216;You can select one of the following datetime types as output:<br />
        &#8216;SYSTEM: &quot;(2 digits day)-(2 digits month)-(4 digits year) hours:minutes:seconds&quot;<br />
        &#8216;MYSQL: &quot;(4 digits year)-(2 digits month)-(2 digits day) hours:minutes:seconds&quot;</p>
<p>        &#8216;examples:<br />
        &#8216;for a regular datetime in input and<br />
        &#8216;a MySql datetime as output, You &#8216;ll get&#8230;</p>
<p>        &#8217;25-1-08 -&gt; 2008-01-25 00:00:00<br />
        &#8217;25/1/08 -&gt; 2008-01-25 00:00:00<br />
        &#8217;25/1/08 12:00 -&gt; 2008-01-25 12:00:00<br />
        &#8217;25-1-08 12:00 -&gt; 2008-01-25 12:00:00<br />
        &#8216;25.1.08 12:00 -&gt; 2008-01-25 12:00:00<br />
        &#8216;25.1.08 12.00 -&gt; 2008-01-25 12:00:00<br />
        &#8216;25.1.08 12.00.23 -&gt; 2008-01-25 12:00:23</p>
<p>        Dim dt_out As String = Nothing<br />
        Dim dt_type As String = &quot;&quot;<br />
        If output_datetime_type = DATETIME_TYPE.MYSQL Then<br />
            dt_type = &quot;yyyy-MM-dd HH&#8217;:&#8217;mm&#8217;:&#8217;ss&quot;<br />
        Else<br />
            dt_type = &quot;dd-MM-yyyy HH&#8217;:&#8217;mm&#8217;:&#8217;ss&quot;<br />
        End If<br />
        Try<br />
            If input_datetime.IndexOf(&quot;.&quot;, 0, CompareMethod.Binary) &gt; 0 Then<br />
                Dim tmp() As String = input_datetime.Split(&quot; &quot;)<br />
                If tmp.GetUpperBound(0) &gt; 0 Then<br />
                    input_datetime = tmp(0).Replace(&quot;.&quot;, &quot;-&quot;) &amp; &quot; &quot; &amp; tmp(1).Replace(&quot;.&quot;, &quot;:&quot;)<br />
                End If<br />
            End If<br />
            Dim myDTFI As DateTimeFormatInfo = New CultureInfo(&quot;it-IT&quot;, False).DateTimeFormat<br />
            myDTFI.FullDateTimePattern = &quot;dd-MM-yyyy HH&#8217;:&#8217;mm&#8217;:&#8217;ss&quot;<br />
            myDTFI.DateSeparator = &quot;-&quot;<br />
            myDTFI.TimeSeparator = &quot;:&quot;<br />
            Dim myDT As New DateTime<br />
            myDT = System.Convert.ToDateTime(input_datetime, myDTFI)<br />
            dt_out = Format(myDT, dt_type)<br />
            myDT = Nothing<br />
            myDTFI = Nothing<br />
            If get_only_date = True Then<br />
                Dim s() As String = dt_out.Split(&quot; &quot;)<br />
                If s.GetUpperBound(0) &gt; 0 Then<br />
                    dt_out = s(0)<br />
                End If<br />
            End If<br />
        Catch ex As Exception<br />
            dt_out = Nothing<br />
        End Try<br />
        Return dt_out</p>
<p>    End Function</p>
<p>End Class</p>
<p>[/sourcecode]</p><p>The post <a href="https://www.maxvergelli.com/mysqlhelper-vb-net-class-execute-commands-against-a-mysql-database/">MySqlHelper VB.NET class – easly execute commands against a MySQL database</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/mysqlhelper-vb-net-class-execute-commands-against-a-mysql-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">45</post-id>	</item>
		<item>
		<title>How to extract text content from tags in VB.Net</title>
		<link>https://www.maxvergelli.com/how-to-extract-text-content-from-tags-in-vb-net/</link>
					<comments>https://www.maxvergelli.com/how-to-extract-text-content-from-tags-in-vb-net/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 27 May 2016 14:56:42 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[String Manipulation Algorithms]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String-class]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=32</guid>

					<description><![CDATA[<p>With this simple vb.net function You are able to extract content from HTML tags, useful and smart Max 🙂 [sourcecode language=&#8221;vb&#8221;] Public Function GetTagContent(ByRef html As String, ByVal start_tag As String, ByVal end_tag As String) As String Dim s As &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-extract-text-content-from-tags-in-vb-net/" aria-label="How to extract text content from tags in VB.Net">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/how-to-extract-text-content-from-tags-in-vb-net/">How to extract text content from tags in VB.Net</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>With this simple vb.net function You are able to extract content from HTML tags, useful and smart</p>
<p>Max 🙂</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
Public Function GetTagContent(ByRef html As String, ByVal start_tag As String, ByVal end_tag As String) As String<br />
Dim s As String = &quot;&quot;<br />
 Dim content() As String = html.Split(start_tag)<br />
 If content.Count &gt; 1 Then<br />
 Dim parts() As String = content(1).Split(end_tag)<br />
 If parts.Count &gt; 1 Then<br />
 s = parts(0)<br />
 End If<br />
 End If<br />
 Return s<br />
End Function<br />
[/sourcecode]</p><p>The post <a href="https://www.maxvergelli.com/how-to-extract-text-content-from-tags-in-vb-net/">How to extract text content from tags in VB.Net</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-extract-text-content-from-tags-in-vb-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">32</post-id>	</item>
		<item>
		<title>Updated version of CryptographyHelper class for .NET Framework 4</title>
		<link>https://www.maxvergelli.com/cryptography-helper-class-for-net-framework-4/</link>
					<comments>https://www.maxvergelli.com/cryptography-helper-class-for-net-framework-4/#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 27 May 2016 14:53:01 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[decryption]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[enumerating]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[hashing]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rijndael]]></category>
		<category><![CDATA[SHA1]]></category>
		<category><![CDATA[SHA256]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=30</guid>

					<description><![CDATA[<p>This updated version of mine “CryptographyHelper” wrapper/helper class supports .NET Framework 4 . With this vb.net class you can easly encrypt/decrypt strings using a robust symmetric Rijndael algorithm or you can get also MD5 or SHA1, SHA256 hash codes of &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/cryptography-helper-class-for-net-framework-4/" aria-label="Updated version of CryptographyHelper class for .NET Framework 4">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/cryptography-helper-class-for-net-framework-4/">Updated version of CryptographyHelper class for .NET Framework 4</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>This updated version of mine “CryptographyHelper” wrapper/helper class supports .NET Framework 4 .</p>
<p>With this vb.net class you can easly encrypt/decrypt strings using a robust <strong>symmetric Rijndael algorithm</strong> or you can get also <strong>MD5</strong> or <strong>SHA1</strong>, <strong>SHA256 hash codes</strong> of a string.</p>
<p>During the encryption, the CryptographyHelper encrypts a clear text and saves it in a binary stream, then converts the binary output in <strong>Hexadecimal or Base64 encoding type</strong> for a string rapresentation. The opposite job during the decryption.</p>
<p>How to use:</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
Imports {project&#8217;s name}.Cryptography</p>
<p>Dim crypt As New CryptographyHelper</p>
<p>&#8216;select your favorite encoding type (Hexadecimal or Base64) for encrypted/decryptet text<br />
&#8216;in output/input;<br />
&#8216;during the encryption, the CryptographyHelper encrypts a clear text and saves it in a<br />
&#8216;binary stream, then converts the binary output in Hexadecimal or Base64 encoding type<br />
&#8216;for a string rapresentation. The opposite job during the decryption.<br />
crypt.EncodingType = CryptographyHelper.ENCODING_TYPE.Hexadecimal</p>
<p>&#8216;choose a password<br />
Dim password As String = &quot;my secret password&quot;</p>
<p>&#8216;encrypt/decrypt strings using a robust symmetric Rijndael algorithm<br />
Dim encrypted_text As String = crypt.Encrypt(&quot;plain text to encrypt&#8230;&quot;, password)<br />
Dim decrypted_text As String = crypt.Decrypt(encrypted_text, password)</p>
<p>&#8216;you can also get an hash of a string<br />
Dim MD5hash As String = crypt.GetHash(&quot;string to hash&quot;, CryptographyHelper.HASH_TYPE.MD5)<br />
Dim SHA1hash As String = crypt.GetHash(&quot;string to hash&quot;, CryptographyHelper.HASH_TYPE.SHA1)<br />
Dim SHA256hash As String = crypt.GetHash(&quot;string to hash&quot;, CryptographyHelper.HASH_TYPE.SHA256)<br />
[/sourcecode]</p>
<p>Enjoy 🙂</p>
<p>Max</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>&#8216;	CryptographyHelper &amp; Cryptography VB.NET classes for .NET Framework 4<br />
&#8216;	http://www.maxvergelli.com/<br />
&#8216;<br />
&#8216;	Copyright (c) 2016 Max Vergelli<br />
&#8216;<br />
&#8216;   Vers. 3.5.1<br />
&#8216;   Date: 23/03/2016<br />
&#8216;<br />
&#8216;   Description:<br />
&#8216;   With the “CryptographyHelper” wrapper class, you can easly encrypt/decrypt strings in<br />
&#8216;   .NET Framework 4 using a robust symmetric Rijndael algorithm or you can get also MD5<br />
&#8216;   or SHA1, SHA256 hash codes of a string.<br />
&#8216;   During the encryption, the CryptographyHelper encrypts a clear text and saves it in a<br />
&#8216;   binary stream, then converts the binary output in Hexadecimal or Base64 encoding type<br />
&#8216;   for a string rapresentation. The opposite job during the decryption.<br />
&#8216;<br />
&#8216;<br />
&#8216;   Usage:<br />
&#8216;<br />
&#8216;   Imports {project&#8217;s name}.Cryptography<br />
&#8216;<br />
&#8216;   Dim crypt As New CryptographyHelper<br />
&#8216;<br />
&#8216;   &#8216;select your favorite encoding type (Hexadecimal or Base64) for encrypted/decryptet text<br />
&#8216;   &#8216;in output/input;<br />
&#8216;   &#8216;during the encryption, the CryptographyHelper encrypts a clear text and saves it in a<br />
&#8216;   &#8216;binary stream, then converts the binary output in Hexadecimal or Base64 encoding type<br />
&#8216;   &#8216;for a string rapresentation. The opposite job during the decryption.<br />
&#8216;   crypt.EncodingType = CryptographyHelper.ENCODING_TYPE.Hexadecimal<br />
&#8216;<br />
&#8216;   &#8216;choose a password<br />
&#8216;   Dim password As String = &quot;my secret password&quot;<br />
&#8216;<br />
&#8216;   encrypt/decrypt strings using a robust symmetric Rijndael algorithm<br />
&#8216;   Dim encrypted_text As String = crypt.Encrypt(&quot;plain text to encrypt&#8230;&quot;, password)<br />
&#8216;   Dim decrypted_text As String = crypt.Decrypt(encrypted_text, password)<br />
&#8216;<br />
&#8216;   &#8216;you can also get an hash of a string<br />
&#8216;   Dim MD5hash As String = crypt.GetHash(&quot;string to hash&quot;, CryptographyHelper.HASH_TYPE.MD5)<br />
&#8216;   Dim SHA1hash As String = crypt.GetHash(&quot;string to hash&quot;, CryptographyHelper.HASH_TYPE.SHA1)<br />
&#8216;   Dim SHA256hash As String = crypt.GetHash(&quot;string to hash&quot;, CryptographyHelper.HASH_TYPE.SHA256)<br />
&#8216;<br />
&#8216;<br />
&#8216;   License:<br />
&#8216;<br />
&#8216;	Permission is hereby granted, free of charge, to any person obtaining a copy<br />
&#8216;	of this software and associated documentation files (the &quot;Software&quot;), to deal<br />
&#8216;	in the Software without restriction, including without limitation the rights<br />
&#8216;	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
&#8216;	copies of the Software, and to permit persons to whom the Software is<br />
&#8216;	furnished to do so, subject to the following conditions:<br />
&#8216;<br />
&#8216;	The above copyright notice and this permission notice shall be included in<br />
&#8216;	all copies or substantial portions of the Software.<br />
&#8216;<br />
&#8216;	THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
&#8216;	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
&#8216;	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
&#8216;	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
&#8216;	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
&#8216;	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
&#8216;	THE SOFTWARE.</p>
<p>Imports System<br />
Imports System.IO<br />
Imports System.Text<br />
Imports System.Security.Cryptography</p>
<p>Namespace Cryptography</p>
<p>    Public Class CryptographyHelper</p>
<p>        Private _encoding As ENCODING_TYPE</p>
<p>        Public Enum ENCODING_TYPE As Integer<br />
            Hexadecimal = 1<br />
            Base64 = 2<br />
        End Enum</p>
<p>        Public Enum HASH_TYPE As Integer<br />
            MD5 = 1<br />
            SHA1 = 2<br />
            SHA256 = 3<br />
            SHA512 = 4<br />
        End Enum</p>
<p>        Public Sub New(Optional ByVal encoding As ENCODING_TYPE = ENCODING_TYPE.Hexadecimal)</p>
<p>            &#8216;by default encryption/hashing outputs hexadecimal strings<br />
            &#8216;and decryption get hexstrings as input<br />
            If encoding &lt;&gt; ENCODING_TYPE.Hexadecimal And encoding &lt;&gt; ENCODING_TYPE.Base64 Then<br />
                encoding = ENCODING_TYPE.Hexadecimal<br />
            End If<br />
            _encoding = encoding</p>
<p>        End Sub</p>
<p>        Public Property EncodingType() As ENCODING_TYPE<br />
            Get<br />
                Return _encoding<br />
            End Get<br />
            Set(ByVal value As ENCODING_TYPE)<br />
                _encoding = value<br />
            End Set<br />
        End Property</p>
<p>        Public Function GetHash(ByRef input As String, Optional ByVal type As HASH_TYPE = HASH_TYPE.MD5) As String</p>
<p>            Dim crypt As New Cryptography<br />
            Dim bytes() As Byte = Nothing<br />
            Select Case type<br />
                Case HASH_TYPE.MD5<br />
                    bytes = crypt.CreateMD5Hash(input)<br />
                Case HASH_TYPE.SHA1<br />
                    bytes = crypt.CreateSHA1Hash(input)<br />
                Case HASH_TYPE.SHA256<br />
                    bytes = crypt.CreateSHA256Hash(input)<br />
                Case HASH_TYPE.SHA512<br />
                    bytes = crypt.CreateSHA512Hash(input)<br />
                Case Else<br />
                    bytes = crypt.CreateMD5Hash(input)<br />
            End Select<br />
            Dim hash As String = &quot;&quot;<br />
            Select Case _encoding<br />
                Case ENCODING_TYPE.Hexadecimal<br />
                    hash = crypt.BytesToHexString(bytes)<br />
                Case ENCODING_TYPE.Base64<br />
                    hash = crypt.BytesToBase64(bytes)<br />
                Case Else<br />
                    hash = crypt.BytesToHexString(bytes)<br />
            End Select<br />
            crypt = Nothing<br />
            Return hash</p>
<p>        End Function</p>
<p>        Public Function Encrypt(ByRef input As String, ByRef password As String) As String</p>
<p>            Dim crypt As New Cryptography(password)<br />
            Dim bytes() As Byte = crypt.Encrypt(input)<br />
            Dim encrypted As String = &quot;&quot;<br />
            If bytes IsNot Nothing Then<br />
                Select Case _encoding<br />
                    Case ENCODING_TYPE.Hexadecimal<br />
                        encrypted = crypt.BytesToHexString(bytes)<br />
                    Case ENCODING_TYPE.Base64<br />
                        encrypted = crypt.BytesToBase64(bytes)<br />
                    Case Else<br />
                        encrypted = crypt.BytesToHexString(bytes)<br />
                End Select<br />
            End If<br />
            crypt = Nothing<br />
            Return encrypted</p>
<p>        End Function</p>
<p>        Public Function Decrypt(ByRef input As String, ByRef password As String) As String</p>
<p>            Dim decrypted As String = &quot;&quot;<br />
            If input.Length &gt; 0 Then<br />
                Dim crypt As New Cryptography(password)<br />
                Dim enc_bytes() As Byte = Nothing<br />
                Select Case _encoding<br />
                    Case ENCODING_TYPE.Hexadecimal<br />
                        enc_bytes = crypt.HexStringToBytes(input)<br />
                    Case ENCODING_TYPE.Base64<br />
                        enc_bytes = crypt.Base64ToBytes(input)<br />
                    Case Else<br />
                        enc_bytes = crypt.HexStringToBytes(input)<br />
                End Select<br />
                decrypted = crypt.Decrypt(enc_bytes)<br />
                crypt = Nothing<br />
            End If<br />
            Return decrypted</p>
<p>        End Function</p>
<p>    End Class</p>
<p>    Public Class Cryptography</p>
<p>        Private _key_str As String = Nothing<br />
        Private _key_byte() As Byte = Nothing<br />
        Private _txt_converter As New UnicodeEncoding<br />
        Private _rijndael As New RijndaelManaged &#8216;&quot;rèin-daal&quot; 🙂</p>
<p>        Public Sub New(Optional ByVal encryption_key As String = &quot;&quot;)</p>
<p>            If encryption_key &lt;&gt; &quot;&quot; Then EncryptionKey = encryption_key</p>
<p>        End Sub</p>
<p>        Protected Overrides Sub Finalize()</p>
<p>            If _txt_converter IsNot Nothing Then<br />
                _txt_converter = Nothing<br />
            End If<br />
            If _rijndael IsNot Nothing Then<br />
                _rijndael = Nothing<br />
            End If<br />
            _key_str = Nothing<br />
            _key_byte = Nothing</p>
<p>        End Sub</p>
<p>        Public Property EncryptionKey() As String</p>
<p>            Get<br />
                Return _key_str<br />
            End Get</p>
<p>            Set(ByVal value As String)</p>
<p>                Try<br />
                    &#8216;set the key string<br />
                    _key_str = value</p>
<p>                    &#8216;set hash in bytes of the key string<br />
                    Dim hash256 As New SHA256Managed<br />
                    _key_byte = hash256.ComputeHash(_txt_converter.GetBytes(_key_str))<br />
                    hash256 = Nothing</p>
<p>                    &#8216;If UBound(_key_byte) &lt; 0 Then Exit Property         &#8216;.NET &lt;= 3.5<br />
                    If _key_byte.GetUpperBound(0) &lt; 0 Then Exit Property &#8216;.NET Framework 4</p>
<p>                    &#8216;set Rijndael Key and IV vector for 256 bit encryption<br />
                    Dim main_key(31) As Byte<br />
                    Dim main_vector(15) As Byte<br />
                    Dim diff_block As Integer = 5<br />
                    _rijndael.KeySize = 256 &#8216;bit</p>
<p>                    Dim n As Integer = 0<br />
                    Dim x As Integer = 0<br />
                    Dim y As Integer = 0</p>
<p>                    &#8216;For n = 0 To UBound(main_key)         &#8216;.NET &lt;= 3.5<br />
                    For n = 0 To main_key.GetUpperBound(0) &#8216;.NET Framework 4</p>
<p>                        main_key(n) = _key_byte(x)<br />
                        &#8216;If n &gt; diff_block And n &lt;= UBound(main_vector) + diff_block Then         &#8216;.NET &lt;= 3.5<br />
                        If n &gt; diff_block And n &lt;= main_vector.GetUpperBound(0) + diff_block Then &#8216;.NET Framework 4<br />
                            main_vector(y) = _key_byte(x)<br />
                            y = y + 1<br />
                        End If<br />
                        x = x + 1</p>
<p>                        &#8216;If x &gt; UBound(_key_byte) Then x = 0         &#8216;.NET &lt;= 3.5<br />
                        If x &gt; _key_byte.GetUpperBound(0) Then x = 0 &#8216;.NET Framework 4</p>
<p>                    Next<br />
                    _rijndael.Key = main_key<br />
                    _rijndael.IV = main_vector</p>
<p>                Catch</p>
<p>                    &#8216;set a blank encryption key then we cannot encrypt/decrypt<br />
                    _key_str = Nothing</p>
<p>                End Try</p>
<p>            End Set</p>
<p>        End Property</p>
<p>        Public Function Encrypt(ByRef clear_text As String) As Byte()</p>
<p>            Dim enc_bytes() As Byte = Nothing<br />
            Try<br />
                If _key_str IsNot Nothing Then<br />
                    &#8216;get byte array from text<br />
                    Dim bytes() As Byte = _txt_converter.GetBytes(clear_text)</p>
<p>                    &#8216;encrypt data<br />
                    Dim encryptor As ICryptoTransform = _rijndael.CreateEncryptor()<br />
                    Dim msEncrypt As New MemoryStream<br />
                    Dim csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)</p>
<p>                    &#8216;write all data to the crypto stream and flush it<br />
                    csEncrypt.Write(bytes, 0, bytes.Length)<br />
                    csEncrypt.FlushFinalBlock()</p>
<p>                    &#8216;get encrypted byte array<br />
                    enc_bytes = msEncrypt.ToArray()</p>
<p>                    msEncrypt = Nothing<br />
                    csEncrypt = Nothing<br />
                End If<br />
            Catch</p>
<p>            End Try</p>
<p>            Return enc_bytes</p>
<p>        End Function</p>
<p>        Public Function Decrypt(ByRef encrypted_text() As Byte) As String</p>
<p>            Dim dec_text As String = Nothing</p>
<p>            Try<br />
                If _key_str IsNot Nothing Then<br />
                    Dim decryptor As ICryptoTransform = _rijndael.CreateDecryptor()<br />
                    Dim msDecrypt As New MemoryStream(encrypted_text)<br />
                    Dim csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)</p>
<p>                    &#8216;prepare buffer<br />
                    Dim bytes() As Byte = New Byte(encrypted_text.Length &#8211; 1) {}</p>
<p>                    &#8216;read the data out of the crypto stream<br />
                    csDecrypt.Read(bytes, 0, bytes.Length)</p>
<p>                    &#8216;convert the byte array back into a string<br />
                    dec_text = _txt_converter.GetString(bytes)</p>
<p>                    &#8216;strip null chars at the end of the string<br />
                    StripNullAtEnd(dec_text)</p>
<p>                    msDecrypt = Nothing<br />
                    csDecrypt = Nothing<br />
                End If<br />
            Catch</p>
<p>            End Try</p>
<p>            Return dec_text</p>
<p>        End Function</p>
<p>        Public Function BytesToBase64(ByRef input_bytes() As Byte) As String</p>
<p>            Dim s As String = Nothing<br />
            Try<br />
                s = Convert.ToBase64String(input_bytes)<br />
            Catch</p>
<p>            End Try<br />
            Return s</p>
<p>        End Function</p>
<p>        Public Function Base64ToBytes(ByRef input_base64 As String) As Byte()</p>
<p>            Dim b() As Byte = Nothing<br />
            Try<br />
                b = Convert.FromBase64String(input_base64)<br />
            Catch</p>
<p>            End Try<br />
            Return b</p>
<p>        End Function</p>
<p>        Public Function BytesToHexString(ByRef input_bytes() As Byte) As String</p>
<p>            Dim s As String = Nothing<br />
            Try<br />
                &#8216;Dim s As String = BitConverter.ToString(input_bytes).Replace(&quot;-&quot;, String.Empty)<br />
                Dim builder As New StringBuilder()<br />
                For i As Integer = 0 To input_bytes.Length &#8211; 1<br />
                    builder.AppendFormat(&quot;{0:x2}&quot;, input_bytes(i))<br />
                Next<br />
                s = builder.ToString()<br />
                builder = Nothing<br />
            Catch</p>
<p>            End Try<br />
            Return s</p>
<p>        End Function</p>
<p>        Public Function HexStringToBytes(ByRef input_hex_string As String) As Byte()</p>
<p>            Dim bytes As Byte() = Nothing<br />
            Try<br />
                &#8216;i variable used to hold position in string<br />
                Dim i As Integer = 0<br />
                &#8216;x variable used to hold byte array element position<br />
                Dim x As Integer = 0<br />
                &#8216;allocate byte array based on half of string length<br />
                bytes = New Byte((input_hex_string.Length)  2 &#8211; 1) {}<br />
                &#8216;loop through the string &#8211; 2 bytes at a time converting<br />
                &#8216;it to decimal equivalent and store in byte array<br />
                While input_hex_string.Length &gt; i + 1<br />
                    Dim lngDecimal As Long = Convert.ToInt32(input_hex_string.Substring(i, 2), 16)<br />
                    bytes(x) = Convert.ToByte(lngDecimal)<br />
                    i = i + 2<br />
                    x += 1<br />
                End While<br />
                &#8216;return the finished byte array of decimal values<br />
            Catch</p>
<p>            End Try<br />
            Return bytes</p>
<p>        End Function</p>
<p>        Public Function CreateMD5Hash(ByRef input As String) As Byte()</p>
<p>            Dim hash As Byte() = Nothing<br />
            Try<br />
                Dim bytes() As Byte = _txt_converter.GetBytes(input)<br />
                Dim objMD5 As New MD5CryptoServiceProvider<br />
                hash = objMD5.ComputeHash(bytes)<br />
                objMD5 = Nothing<br />
            Catch</p>
<p>            End Try<br />
            Return hash</p>
<p>        End Function</p>
<p>        Public Function CreateSHA1Hash(ByRef input As String) As Byte()</p>
<p>            Dim hash As Byte() = Nothing<br />
            Try<br />
                Dim bytes() As Byte = _txt_converter.GetBytes(input)<br />
                Dim objSHA As New SHA1CryptoServiceProvider<br />
                hash = objSHA.ComputeHash(bytes)<br />
                objSHA = Nothing<br />
            Catch</p>
<p>            End Try<br />
            Return hash</p>
<p>        End Function</p>
<p>        Public Function CreateSHA256Hash(ByRef input As String) As Byte()<br />
            Dim hash As Byte() = Nothing<br />
            Try<br />
                Dim bytes() As Byte = _txt_converter.GetBytes(input)<br />
                Dim objSHA As New SHA256CryptoServiceProvider<br />
                hash = objSHA.ComputeHash(bytes)<br />
                objSHA = Nothing<br />
            Catch</p>
<p>            End Try<br />
            Return hash</p>
<p>        End Function</p>
<p>        Public Function CreateSHA512Hash(ByRef input As String) As Byte()<br />
            Dim hash As Byte() = Nothing<br />
            Try<br />
                Dim bytes() As Byte = _txt_converter.GetBytes(input)<br />
                Dim objSHA As New SHA512CryptoServiceProvider<br />
                hash = objSHA.ComputeHash(bytes)<br />
                objSHA = Nothing<br />
            Catch</p>
<p>            End Try<br />
            Return hash</p>
<p>        End Function</p>
<p>        Private Sub StripNullAtEnd(ByRef input_string As String)</p>
<p>            Dim nullchar As Char = Convert.ToChar(0) &#8216;&amp;H0<br />
            If input_string.Length &gt; 0 And input_string.EndsWith(nullchar.ToString) Then<br />
                Dim n As Long<br />
                For n = input_string.Length &#8211; 1 To 0 Step -1<br />
                    If input_string.Chars(n) &lt;&gt; nullchar Then<br />
                        input_string = input_string.Substring(0, n + 1)<br />
                        Exit For<br />
                    End If<br />
                Next<br />
            End If<br />
            Convert.ToString(input_string)</p>
<p>        End Sub</p>
<p>    End Class</p>
<p>End Namespace</p>
<p>[/sourcecode]</p><p>The post <a href="https://www.maxvergelli.com/cryptography-helper-class-for-net-framework-4/">Updated version of CryptographyHelper class for .NET Framework 4</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/cryptography-helper-class-for-net-framework-4/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">30</post-id>	</item>
		<item>
		<title>Useful extension methods for the String .Net class and string manipulation, with support of IntelliSense</title>
		<link>https://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/</link>
					<comments>https://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 27 May 2016 14:33:08 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[intellisense]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[String-class]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=26</guid>

					<description><![CDATA[<p>Hi to all, I wrote this .NET module that extends String class with useful methods to modify alphanumeric characters and symbols. It fully integrates with the compiler so You are able to recognize extension methods by IntelliSense; in the bottom &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/" aria-label="Useful extension methods for the String .Net class and string manipulation, with support of IntelliSense">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/">Useful extension methods for the String .Net class and string manipulation, with support of IntelliSense</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hi to all, I wrote this .NET module that extends String class with useful methods to modify alphanumeric characters and symbols. It fully integrates with the compiler so You are able to recognize extension methods by IntelliSense; in the bottom of the article, see the module&#8217;s code.</p>
<p>This is an example of what you can do:</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
&#8216;remove accent marks (ex. &quot;à&quot; to &quot;a&quot;)<br />
Dim accents As String = &quot;àèìòù&quot;<br />
accents = accents.StripAccentMarks()</p>
<p>&#8216;remove tags (ex. &quot;&lt;b&gt;test&lt;/b&gt;&quot; to &quot;test&quot;)<br />
Dim tags As String = &quot;&lt;b&gt;test&lt;/b&gt;&quot;<br />
tags = tags.StripTags()</p>
<p>&#8216;remove symbols from the string but leave &quot;,&quot; and &quot;;&quot; then trim the spaces<br />
Dim s As String = &quot; hi, this   is a test;   5 is a number! &#8211; up-to-date example.   &quot;<br />
Dim symbols_exceptions() As Char = {&quot;,&quot;, &quot;;&quot;}<br />
Dim new_string As String = s.StripNonAlphanumeric(Nothing, symbols_exceptions).TrimSpaces</p>
<p>&#8216;remove punctuation but not hyphens in words<br />
Dim h As String = &quot;punctuation and hyphens, as &#8216;-&#8216;, will be deleted but not hyphens in words like &#8216;up-to-date&#8217;.&quot;<br />
Dim filtered As String = h.StripPunctuation(True)</p>
<p>&#8216;padding strings&#8230;<br />
Dim mystring1 As String = &quot;max&quot;<br />
Dim mystring2 As String = &quot;vergelli&quot;<br />
Console.WriteLine(mystring1.Pad(10, &quot;.&quot;) &amp; vbCrLf &amp; mystring2.Pad(10, &quot;.&quot;))<br />
&#8216;it will print<br />
&#8216;   &quot;&#8230;&#8230;.max&quot;<br />
&#8216;   &quot;..vergelli&quot;</p>
<p>&#8216;padding integers&#8230;<br />
Dim mynumber1 As Integer = 10<br />
Dim mynumber2 As Integer = 1000<br />
Console.WriteLine(mynumber1.Pad(10, &quot;0&quot;) &amp; vbCrLf &amp; mynumber2.Pad(10, &quot;0&quot;))<br />
&#8216;it will print<br />
&#8216;   &quot;0000000010&quot;<br />
&#8216;   &quot;0000001000&quot;</p>
<p>&#8216;get the first 3 characters of the string<br />
Dim ls As String = s.Left(3)</p>
<p>&#8216;get the last 3 characters of the string<br />
Dim rs As String = s.Right(3)</p>
<p>&#8216;get characters in the middle of the string<br />
Dim ms As String = s.Mid(5, 3)</p>
<p>&#8216;get only the symbols<br />
Dim symbols As String = s.StripAlphanumeric()</p>
<p>&#8216;leave only one space between words but it does not trim spaces at start and at end of the string<br />
symbols = symbols.TrimSpaces(True, True)</p>
<p>&#8216;get only the numbers<br />
Dim numbers As String = s.StripNonNumeric()</p>
<p>Dim n As String = &quot;5&quot;<br />
If n.IsNumeric Then Console.WriteLine(&quot;&#8217;n&#8217; variable contains a numeric value.&quot;)</p>
<p>&#8216;convert a string to an integer&#8230;<br />
n = n.ToInteger()<br />
[/sourcecode]</p>
<p><strong>How to install the module:</strong></p>
<p>all that is required to be able to run these extension methods is that they be in scope, therefore  You have to import this module in your classes with the header &#8220;Imports [Project&#8217;s name].Extensions&#8221;, so all methods will be visible also in IntelliSense.</p>
<p>Notes:</p>
<ul>
<li>All the methods do not change the value of the current instance, instead, they return always a new string.</li>
<li>Only an instance of String can use the these methods, any other class trying to use the string extension methods will throw a compilation error.</li>
<li>If an extension method is called for an object that is set to Nothing, the extension method executes. This does not apply to ordinary instance methods. You can explicitly check for Nothing in the extension method.</li>
<li>Notice that when the extension methods are invoked, You have to omit the first parameter; Why no argument is sent in for the first parameter? The first parameter in the method definitions is only bound to caller object (the instance of String that calls them), so the compiler will treat the argument in the first parameter (named &#8220;instance_handler&#8221;) as the caller object.</li>
</ul>
<p><strong>Finally, the source code of the module, enjoy!</strong>&#8230;  🙂</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
&#8216;    StringExtensions VB.NET module<br />
&#8216;    http://www.maxvergelli.com/</p>
<p>&#8216;    Copyright (c) 2016 Max Vergelli</p>
<p>&#8216;   Vers. 3.0.0<br />
&#8216;   Date: 22/03/2016</p>
<p>&#8216;   Description:<br />
&#8216;   .NET module that extends String class with useful methods to modify<br />
&#8216;   alphanumeric characters and symbols. It fully integrates with the compiler<br />
&#8216;   so You are able to recognize extension methods by IntelliSense.<br />
&#8216;<br />
&#8216;<br />
&#8216;   License:<br />
&#8216;<br />
&#8216;    Permission is hereby granted, free of charge, to any person obtaining a copy<br />
&#8216;    of this software and associated documentation files (the &quot;Software&quot;), to deal<br />
&#8216;    in the Software without restriction, including without limitation the rights<br />
&#8216;    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
&#8216;    copies of the Software, and to permit persons to whom the Software is<br />
&#8216;    furnished to do so, subject to the following conditions:</p>
<p>&#8216;    The above copyright notice and this permission notice shall be included in<br />
&#8216;    all copies or substantial portions of the Software.</p>
<p>&#8216;    THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
&#8216;    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
&#8216;    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
&#8216;    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
&#8216;    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
&#8216;    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
&#8216;    THE SOFTWARE.<br />
&#8216;<br />
&#8216;<br />
&#8216;   Installation:<br />
&#8216;<br />
&#8216;   All that is required to be able to run these extension methods is that they be in scope, therefore<br />
&#8216;   You have to import this module in your classes with the header &quot;Imports [Project&#8217;s name].Extensions&quot;,<br />
&#8216;   so all methods will be visible also in IntelliSense.<br />
&#8216;<br />
&#8216;<br />
&#8216;   Notes:<br />
&#8216;<br />
&#8216;   1) All the methods do not change the value of the current instance, instead, they return always a new string.</p>
<p>&#8216;   2) Only an instance of String can use the these methods, any other class trying to use the string extension<br />
&#8216;      methods will throw a compilation error.<br />
&#8216;<br />
&#8216;   3) If an extension method is called for an object that is set to Nothing, the extension method executes. This<br />
&#8216;      does not apply to ordinary instance methods. You can explicitly check for Nothing in the extension method.<br />
&#8216;<br />
&#8216;   4) Notice that when the extension methods are invoked, You have to omit the first parameter;<br />
&#8216;      Why no argument is sent in for the first parameter?<br />
&#8216;      The first parameter in the method definitions is only bound to caller object (the instance of String that<br />
&#8216;      calls them), so the compiler will treat the argument in the first parameter (named &quot;instance_handler&quot;) as<br />
&#8216;      the caller object.<br />
&#8216;<br />
&#8216;<br />
&#8216;   Usage:<br />
&#8216;<br />
&#8216;   Imports {Your project&#8217;s name}.Extensions<br />
&#8216;<br />
&#8216;   Public Class Test<br />
&#8216;       Public Sub TestExtensions()<br />
&#8216;<br />
&#8216;        &#8216;remove accent marks (ex. &quot;à&quot; to &quot;a&quot;)<br />
&#8216;        Dim accents As String = &quot;àèìòù&quot;<br />
&#8216;        accents = accents.StripAccentMarks()<br />
&#8216;<br />
&#8216;        &#8216;remove tags (ex. &quot;&lt;b&gt;test&lt;/b&gt;&quot; to &quot;test&quot;)<br />
&#8216;        Dim tags As String = &quot;&lt;b&gt;test&lt;/b&gt;&quot;<br />
&#8216;        tags = tags.StripTags()<br />
&#8216;<br />
&#8216;        &#8216;remove symbols from the string but leave &quot;,&quot; and &quot;;&quot; then trim the spaces<br />
&#8216;        Dim s As String = &quot; hi, this   is a test;   5 is a number! &#8211; up-to-date example.   &quot;<br />
&#8216;        Dim symbols_exceptions() As Char = {&quot;,&quot;, &quot;;&quot;}<br />
&#8216;        Dim new_string As String = s.StripNonAlphanumeric(Nothing, symbols_exceptions).TrimSpaces<br />
&#8216;<br />
&#8216;        &#8216;remove punctuation but not hyphens in words<br />
&#8216;        Dim h As String = &quot;punctuation and hyphens, as &#8216;-&#8216;, will be deleted but not hyphens in words like &#8216;up-to-date&#8217;.&quot;<br />
&#8216;        Dim filtered As String = h.StripPunctuation(True)<br />
&#8216;<br />
&#8216;        &#8216;padding strings&#8230;<br />
&#8216;        Dim mystring1 As String = &quot;max&quot;<br />
&#8216;        Dim mystring2 As String = &quot;vergelli&quot;<br />
&#8216;        Console.WriteLine(mystring1.Pad(10, &quot;.&quot;) &amp; vbCrLf &amp; mystring2.Pad(10, &quot;.&quot;))<br />
&#8216;        &#8216;it will print<br />
&#8216;        &#8216;   &quot;&#8230;&#8230;.max&quot;<br />
&#8216;        &#8216;   &quot;..vergelli&quot;<br />
&#8216;<br />
&#8216;        &#8216;padding integers&#8230;<br />
&#8216;        Dim mynumber1 As Integer = 10<br />
&#8216;        Dim mynumber2 As Integer = 1000<br />
&#8216;        Console.WriteLine(mynumber1.Pad(10, &quot;0&quot;) &amp; vbCrLf &amp; mynumber2.Pad(10, &quot;0&quot;))<br />
&#8216;        &#8216;it will print<br />
&#8216;        &#8216;   &quot;0000000010&quot;<br />
&#8216;        &#8216;   &quot;0000001000&quot;<br />
&#8216;<br />
&#8216;        &#8216;get the first 3 characters of the string<br />
&#8216;        Dim ls As String = s.Left(3)<br />
&#8216;<br />
&#8216;        &#8216;get the last 3 characters of the string<br />
&#8216;        Dim rs As String = s.Right(3)<br />
&#8216;<br />
&#8216;        &#8216;get characters in the middle of the string<br />
&#8216;        Dim ms As String = s.Mid(5, 3)<br />
&#8216;<br />
&#8216;        &#8216;get only the symbols<br />
&#8216;        Dim symbols As String = s.StripAlphanumeric()<br />
&#8216;<br />
&#8216;        &#8216;leave only one space between words but it does not trim spaces at start and at end of the string<br />
&#8216;        symbols = symbols.TrimSpaces(True, True)<br />
&#8216;<br />
&#8216;        &#8216;get only the numbers<br />
&#8216;        Dim numbers As String = s.StripNonNumeric()<br />
&#8216;<br />
&#8216;        Dim n As String = &quot;5&quot;<br />
&#8216;        If n.IsNumeric Then Console.WriteLine(&quot;&#8217;n&#8217; variable contains a numeric value.&quot;)<br />
&#8216;<br />
&#8216;        &#8216;convert a string to an integer&#8230;<br />
&#8216;        n = n.ToInteger()<br />
&#8216;<br />
&#8216;       End Sub<br />
&#8216;   End Class</p>
<p>Imports System.Runtime.CompilerServices<br />
Imports System.Text<br />
Imports System.Text.RegularExpressions<br />
Imports System.Web</p>
<p>Namespace Extensions</p>
<p>Module StringExtensions</p>
<p>&lt;Extension()&gt; _<br />
Public Function IsNumeric(ByRef instance_handler As Object) As Boolean<br />
Dim is_numeric As Boolean = False<br />
&#8216;Define variable to collect out parameter of the TryParse method.<br />
&#8216;If the conversion fails, the out parameter is zero.<br />
Dim tmp As Double<br />
&#8216;The TryParse method converts a string in a specified style and culture-specific format to its<br />
&#8216;double-precision floating point number equivalent.<br />
&#8216;The TryParse method does not generate an exception if the conversion fails. If the conversion passes,<br />
&#8216;True is returned. If it does not, False is returned.<br />
is_numeric = [Double].TryParse(Convert.ToString(instance_handler), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, tmp)<br />
Return is_numeric<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function ToInteger(ByRef instance_handler As String) As Integer<br />
Return Integer.Parse(instance_handler)<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function Left(ByRef instance_handler As String, length As Integer) As String<br />
Return instance_handler.Substring(0, length)<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function Right(ByRef instance_handler As String, length As Integer) As String<br />
Return instance_handler.Substring(instance_handler.Length &#8211; length, length)<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function Mid(ByRef instance_handler As String, start_index As Integer, length As Integer) As String<br />
Return instance_handler.Substring(start_index, length)<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripNonAlphanumeric(ByRef instance_handler As String, _<br />
Optional ByVal replace_nonalphanumeric_with As String = Nothing, _<br />
Optional ByVal nonalphanumeric_exceptions() As Char = Nothing) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To h.Length &#8211; 1<br />
c = h.Chars(i)<br />
If Char.IsLetterOrDigit(c) = True Then<br />
s.Append(c)<br />
Else<br />
If nonalphanumeric_exceptions IsNot Nothing AndAlso nonalphanumeric_exceptions.Contains(c) Then<br />
s.Append(c)<br />
ElseIf replace_nonalphanumeric_with IsNot Nothing Then<br />
s.Append(replace_nonalphanumeric_with)<br />
End If<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripAlphanumeric(ByRef instance_handler As String) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To h.Length &#8211; 1<br />
c = h.Chars(i)<br />
If Char.IsLetterOrDigit(c) = False Then<br />
s.Append(c)<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripAlphabetic(ByRef instance_handler As String) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To h.Length &#8211; 1<br />
c = h.Chars(i)<br />
If Char.IsLetter(c) = False Then<br />
s.Append(c)<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripNumeric(ByRef instance_handler As String) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To h.Length &#8211; 1<br />
c = h.Chars(i)<br />
If Char.IsDigit(c) = False Then<br />
s.Append(c)<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripNonNumeric(ByRef instance_handler As String) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To h.Length &#8211; 1<br />
c = h.Chars(i)<br />
If Char.IsDigit(c) = True Then<br />
s.Append(c)<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripPunctuation(ByRef instance_handler As String, _<br />
Optional ByVal preserve_only_hyphenated_words As Boolean = False, _<br />
Optional ByVal punctuation_exceptions() As Char = Nothing) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
Dim hyphens As List(Of Char) = New List(Of Char)(New Char() {&quot;_&quot;c, &quot;-&quot;c, &quot;‐&quot;c, &quot;‒&quot;c, &quot;–&quot;c, &quot;—&quot;c, &quot;―&quot;c})<br />
For i As Integer = 0 To h.Length &#8211; 1<br />
c = h.Chars(i)<br />
If Char.IsPunctuation(c) = False Or (punctuation_exceptions IsNot Nothing AndAlso punctuation_exceptions.Contains(c)) Then<br />
s.Append(c)<br />
ElseIf preserve_only_hyphenated_words = True AndAlso hyphens.Contains(c) _<br />
AndAlso i &#8211; 1 &gt; -1 AndAlso i + 1 &lt; h.Length _<br />
AndAlso Char.IsLetterOrDigit(h.Chars(i &#8211; 1)) AndAlso Char.IsLetterOrDigit(h.Chars(i + 1)) Then<br />
s.Append(c)<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripSpaces(ByRef instance_handler As String, Optional ByVal replace_space_with As String = &quot;&quot;) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim r As New Regex(&quot;(s+)&quot;, RegexOptions.Compiled And RegexOptions.IgnoreCase And RegexOptions.Singleline)<br />
Dim s As String = r.Replace(h, replace_space_with)<br />
r = Nothing<br />
Return s<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function TrimSpaces(ByRef instance_handler As String, _<br />
Optional StripSpaceAtStart As Boolean = True, _<br />
Optional StripSpaceAtEnd As Boolean = True) As String<br />
Dim h As String = instance_handler.Trim<br />
Dim r As New Regex(&quot;(s+)&quot;, RegexOptions.Compiled And RegexOptions.IgnoreCase And RegexOptions.Singleline)<br />
Dim s As String = r.Replace(h, &quot; &quot;)<br />
If StripSpaceAtStart = True Then<br />
s = s.TrimStart(&quot; &quot;c)<br />
End If<br />
If StripSpaceAtEnd = True Then<br />
s = s.TrimEnd(&quot; &quot;c)<br />
End If<br />
r = Nothing<br />
Return s<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function ReplaceGermanUmlauts(ByRef instance_handler As String) As String<br />
Dim s As String = instance_handler<br />
s = s.Replace(&quot;ä&quot;, &quot;ae&quot;)<br />
s = s.Replace(&quot;ö&quot;, &quot;oe&quot;)<br />
s = s.Replace(&quot;ü&quot;, &quot;ue&quot;)<br />
s = s.Replace(&quot;Ä&quot;, &quot;Ae&quot;)<br />
s = s.Replace(&quot;Ö&quot;, &quot;Oe&quot;)<br />
s = s.Replace(&quot;Ü&quot;, &quot;Ue&quot;)<br />
s = s.Replace(&quot;ß&quot;, &quot;ss&quot;)<br />
Return s<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripAccentMarks(ByRef instance_handler As String) As String<br />
Dim n_s As String = instance_handler.Normalize(NormalizationForm.FormD)<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To n_s.Length &#8211; 1<br />
c = Convert.ToChar(n_s(i))<br />
If System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) &lt;&gt; System.Globalization.UnicodeCategory.NonSpacingMark Then<br />
s.Append(c)<br />
End If<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function StripTags(ByRef instance_handler As String) As String<br />
Dim b As Boolean = False<br />
Dim s As New StringBuilder()<br />
Dim c As Char<br />
For i As Integer = 0 To instance_handler.Length &#8211; 1<br />
c = instance_handler.Chars(i)<br />
If c = &quot;&lt;&quot;c Then b = True<br />
If Not b Then s.Append(c)<br />
If c = &quot;&gt;&quot;c Then b = False<br />
Next<br />
Return s.ToString<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function SpecialCharsToHtmlEntities(ByRef instance_handler As String) As String<br />
Return HttpUtility.HtmlEncode(instance_handler)<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function HtmlEntitiesToSpecialChars(ByRef instance_handler As String) As String<br />
Return HttpUtility.HtmlDecode(instance_handler)<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function Pad(ByRef instance_handler As String, ByVal length As Integer, Optional ByVal padding_char As Char = &quot; &quot;c) As String<br />
Dim s As String = String.Empty<br />
If length &gt; instance_handler.Length Then<br />
s = instance_handler.PadLeft(length, padding_char)<br />
Else<br />
s = instance_handler.Substring(length &#8211; 1)<br />
End If<br />
Return s<br />
End Function</p>
<p>&lt;Extension()&gt; _<br />
Public Function Pad(ByRef instance_handler As Integer, ByVal length As Integer, Optional ByVal padding_char As Char = &quot;0&quot;c) As String<br />
Dim s As String = String.Empty<br />
Dim nb As String = instance_handler.ToString<br />
If length &gt; nb.Length Then<br />
s = nb.PadLeft(length, padding_char)<br />
Else<br />
s = nb.Substring(length &#8211; 1)<br />
End If<br />
Return s<br />
End Function</p>
<p>End Module</p>
<p>End Namespace<br />
[/sourcecode]</p><p>The post <a href="https://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/">Useful extension methods for the String .Net class and string manipulation, with support of IntelliSense</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">26</post-id>	</item>
		<item>
		<title>The fastest algorithm in C#/VB.Net to count how many times a value is repeated in a List of items</title>
		<link>https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/</link>
					<comments>https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 27 May 2016 13:57:51 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[enumerating]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=24</guid>

					<description><![CDATA[<p>The faster way (with the best system performance) to count how many times a particular value is repeated in a List of items, it&#8217;s like this [sourcecode language=&#8221;vb&#8221;] Const chars As String = &#34;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&#34; Dim rnd As New Random() &#8216;create &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/" aria-label="The fastest algorithm in C#/VB.Net to count how many times a value is repeated in a List of items">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/">The fastest algorithm in C#/VB.Net to count how many times a value is repeated in a List of items</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The faster way (with the best system performance) to count how many times a particular value is repeated in a List of items, it&#8217;s like this</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
Const chars As String = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;<br />
Dim rnd As New Random()</p>
<p>&#8216;create a long list of random letters<br />
Dim random_letters As List(Of String) = Enumerable.Range(1, 100000).Select(Function(i) chars(rnd.Next(0, chars.Length)).ToString).ToList</p>
<p>&#8216;create a long list of random numbers<br />
Dim random_numbers As List(Of Integer) = Enumerable.Range(1, 100000).Select(Function(i) rnd.Next(100000)).ToList()</p>
<p>&#8216;get a lookup table<br />
Dim lookup_table = random_letters.GetLookupTable</p>
<p>&#8216;count how many times a particular value &quot;B&quot; is repeated in the lookup table of random_letters List<br />
Dim count As Integer = lookup_table.CountValue(&quot;B&quot;)<br />
[/sourcecode]</p>
<p>To do that, You have to add the following two extension methods, <strong>optimized for the best performance</strong>, to my .Net module (at <a href="http://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/">http://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/</a>) that extends the String class</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
 &#8216;CountValue() count how many times a particular value is repeated in a lookup table</p>
<p>         _<br />
        Public Function CountValue(Of T)(ByRef lookup_table As Dictionary(Of T, Int32), ByRef value As T) As Integer<br />
            Dim c As Integer = 0<br />
            lookup_table.TryGetValue(value, c)<br />
            Return c<br />
        End Function</p>
<p>        &#8216;get a lookup table from a List of items</p>
<p>         _<br />
        Public Function GetLookupTable(Of T)(ByRef list As List(Of T)) As Dictionary(Of T, Int32)<br />
            Dim table As New Dictionary(Of T, Integer)<br />
            For Each s As T In list<br />
                Dim count As Int32 = 0<br />
                If table.TryGetValue(s, count) Then<br />
                    table(s) = count + 1<br />
                Else<br />
                    table(s) = 1<br />
                End If<br />
            Next<br />
            Return table<br />
        End Function<br />
[/sourcecode]</p>
<p>Enjoy,<br />
Max 🙂</p><p>The post <a href="https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/">The fastest algorithm in C#/VB.Net to count how many times a value is repeated in a List of items</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">24</post-id>	</item>
	</channel>
</rss>
