<?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>vb.net &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/vb-net/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Sat, 11 Apr 2020 15:54:53 +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>vb.net &#8211; 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>Render a Section in a Partial View &#8211; ASP.Net MVC</title>
		<link>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/</link>
					<comments>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sun, 12 Apr 2020 15:34:00 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvc-partial-view]]></category>
		<category><![CDATA[mvc-project]]></category>
		<category><![CDATA[mvc-view]]></category>
		<category><![CDATA[partial-view]]></category>
		<category><![CDATA[razor]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[section]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=231</guid>

					<description><![CDATA[Let&#8217;s start with the following configuration to give an example: in a MVC project, you have a &#8220;_Layout.vbhtml&#8221; file with this code Then, you have a Partial View &#8220;ValidationScripts.vbhtml&#8221; in the Shared folder with If you call the Partial View &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/" aria-label="Render a Section in a Partial View &#8211; ASP.Net MVC">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>Let&#8217;s start with the following configuration to give an example: in a MVC project, you have a &#8220;_Layout.vbhtml&#8221; file with this code</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
	&lt;!-- some code here --&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.8.2.min.js&quot;)&quot;&gt;		&lt;/script&gt;
    @RenderSection(&quot;Scripts&quot;, false)
  &lt;/body&gt;
&lt;/html&gt;</pre></div>



<p>Then, you have a Partial View &#8220;ValidationScripts.vbhtml&#8221; in the Shared folder with</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@Section Scripts
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.min.js&quot;)&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.unobtrusive.min.js&quot;)&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.fix.js&quot;)&quot;&gt;&lt;/script&gt;  
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/localization/messages_de.js&quot;)&quot;&gt;&lt;/script&gt;      
End Section</pre></div>



<p>If you call the Partial View from a View like this…</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@ModelType MvcExample.MyModel
@Code
    ViewData(&quot;Title&quot;) = &quot;Test&quot;
End Code

@Html.Partial(&quot;ValidationScripts&quot;)

&lt;h2&gt;Just a Test&lt;/h2&gt;</pre></div>



<p>However the Section &#8220;Scripts&#8221; is not rendered on the page, and the output HTML will be&#8230;</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
    
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.8.2.min.js&quot;)&quot;&gt;&lt;/script&gt;

  &lt;/body&gt;
&lt;/html&gt;</pre></div>



<p><strong>Solution</strong></p>



<p>To render the Section in the Partial View, you need to create a couple of Extension methods like this:</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">public static class HtmlHelperExtensions
{
  private const string _jSViewDataName = &quot;RenderJavaScript&quot;;
  private const string _styleViewDataName = &quot;RenderStyle&quot;;

  public static void AddJavaScript(this HtmlHelper htmlHelper, 
                                   string scriptURL)
  {
    List&lt;string&gt; scriptList = htmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._jSViewDataName] as List&lt;string&gt;;
    if (scriptList != null)
    {
      if (!scriptList.Contains(scriptURL))
      {
        scriptList.Add(scriptURL);
      }
    }
    else
    {
      scriptList = new List&lt;string&gt;();
      scriptList.Add(scriptURL);
      htmlHelper.ViewContext.HttpContext
        .Items.Add(HtmlHelperExtensions._jSViewDataName, scriptList);
    }
  }

  public static MvcHtmlString RenderJavaScripts(this HtmlHelper HtmlHelper)
  {
    StringBuilder result = new StringBuilder();

    List&lt;string&gt; scriptList = HtmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._jSViewDataName] as List&lt;string&gt;;
    if (scriptList != null)
    {
      foreach (string script in scriptList)
      {
        result.AppendLine(string.Format(
          &quot;&lt;script type=\&quot;text/javascript\&quot; src=\&quot;{0}\&quot;&gt;&lt;/script&gt;&quot;, 
          script));
      }
    }

    return MvcHtmlString.Create(result.ToString());
  }

  public static void AddStyle(this HtmlHelper htmlHelper, string styleURL)
  {
    List&lt;string&gt; styleList = htmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._styleViewDataName] as List&lt;string&gt;;

   if (styleList != null)
   {
     if (!styleList.Contains(styleURL))
     {
       styleList.Add(styleURL);
     }
   }
   else
   {
     styleList = new List&lt;string&gt;();
     styleList.Add(styleURL);
     htmlHelper.ViewContext.HttpContext
       .Items.Add(HtmlHelperExtensions._styleViewDataName, styleList);
   }
 }

 public static MvcHtmlString RenderStyles(this HtmlHelper htmlHelper)
 {
   StringBuilder result = new StringBuilder();

   List&lt;string&gt; styleList = htmlHelper.ViewContext.HttpContext
     .Items[HtmlHelperExtensions._styleViewDataName] as List&lt;string&gt;;

   if (styleList != null)
   {
     foreach (string script in styleList)
     {
       result.AppendLine(string.Format(
         &quot;&lt;link href=\&quot;{0}\&quot; rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; /&gt;&quot;, 
         script));
     }
   }

  return MvcHtmlString.Create(result.ToString());
  }
}</pre></div>



<p>So, on any View or Partial View or Display/Edit Template you simply add what you need:</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@{
  Html.AddJavaScript(&quot;http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js&quot;);
}</pre></div>



<p>Then, in your Layouts you render it where you want it! Like this markup&#8230;</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
  @Html.RenderStyles()
  @Html.RenderJavascripts()</pre></div>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">231</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[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>]]></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>
]]></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 draw a shadow for a bitmap (Drop Shadow Effect in VB.NET / ASP.NET)</title>
		<link>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/</link>
					<comments>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Thu, 09 Jan 2020 15:41:16 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[backcolor]]></category>
		<category><![CDATA[background-color]]></category>
		<category><![CDATA[bitamp-library]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[bitmap-effect]]></category>
		<category><![CDATA[bitmap-fx]]></category>
		<category><![CDATA[bitmap-manipulation]]></category>
		<category><![CDATA[bitmap-processing]]></category>
		<category><![CDATA[bitmap-programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[digital-image-processing]]></category>
		<category><![CDATA[draw]]></category>
		<category><![CDATA[draw-bitmap]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[drop-shadow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[graphic-manipulation]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[image-filter]]></category>
		<category><![CDATA[image-fx]]></category>
		<category><![CDATA[image-height]]></category>
		<category><![CDATA[image-library]]></category>
		<category><![CDATA[image-manipulation]]></category>
		<category><![CDATA[image-manipulation-algorithm]]></category>
		<category><![CDATA[image-matrix]]></category>
		<category><![CDATA[image-processing]]></category>
		<category><![CDATA[image-processing-algorithm]]></category>
		<category><![CDATA[image-width]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[matrix-manipulation]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shadow]]></category>
		<category><![CDATA[shadow-effect]]></category>
		<category><![CDATA[thread-safe]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=72</guid>

					<description><![CDATA[I wrote a vb.net subroutine to draw easly a shadow for a Bitmap object; It is possible get a charming shadow in different ways&#8230; Normal black shadow to the bottom right corner Red shadow to the bottom right corner Shadow &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/" aria-label="How to draw a shadow for a bitmap (Drop Shadow Effect in VB.NET / ASP.NET)">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>I wrote a vb.net subroutine to draw easly a shadow for a Bitmap object; It is possible get a charming shadow in different ways&#8230;</p>
<table>
<tbody>
<tr>
<td>Normal black shadow to the bottom right corner</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_01_black_to_white.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Red shadow to the bottom right corner</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_02_red_to_white.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the bottom left corner</td>
<td><img src="https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_04_d_bottomleft.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the top left corner</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_05_d_topleft.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the top right corner</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_06_d_topright.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221;</td>
<td><img src="https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_07_opacity.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221; and Softness: &#8220;8&#8221;</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_08_opacityandsoftness.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221;, Softness: &#8220;8&#8221; and Distance: &#8220;10&#8221;</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_09_opacitysoftnessanddistance.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow without rounded edges</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_10_noroundededges.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
</tbody>
</table>
<p>Copy and paste my following vb.net code in your application. it does all the hard job&#8230;</p>
<p>[sourcecode language=&#8221;vb&#8221;]</p>
<p>    &#8216;ShadowDirection:<br />
    &#8216;       TOP_RIGHT = 1<br />
    &#8216;       BOTTOM_RIGHT = 2<br />
    &#8216;       BOTTOM_LEFT = 3<br />
    &#8216;       TOP_LEFT = 4<br />
    &#8216;ShadowOpacity: from 0 to 255<br />
    &#8216;ShadowSoftness: from 1 to 30<br />
    &#8216;ShadowDistance: from 1 to 50<br />
    &#8216;ShadowRoundedEdges: True or False</p>
<p>    &#8216;Note:<br />
    &#8216;If You set &quot;transparent&quot; as background color, this is replaced with white color.</p>
<p>    Public Enum ShadowDirections As Integer<br />
        TOP_RIGHT = 1<br />
        BOTTOM_RIGHT = 2<br />
        BOTTOM_LEFT = 3<br />
        TOP_LEFT = 4<br />
    End Enum</p>
<p>    &lt;STAThread()&gt; _<br />
    Public Sub DropShadow(ByRef SourceImage As Drawing.Bitmap, _<br />
                            ByVal ShadowColor As Drawing.Color, _<br />
                            ByVal BackgroundColor As Drawing.Color, _<br />
                            Optional ByVal ShadowDirection As ShadowDirections = _<br />
                                                  ShadowDirections.BOTTOM_RIGHT, _<br />
                            Optional ByVal ShadowOpacity As Integer = 190, _<br />
                            Optional ByVal ShadowSoftness As Integer = 4, _<br />
                            Optional ByVal ShadowDistance As Integer = 5, _<br />
                            Optional ByVal ShadowRoundedEdges As Boolean = True)<br />
        Dim ImgTarget As Bitmap = Nothing<br />
        Dim ImgShadow As Bitmap = Nothing<br />
        Dim g As Graphics = Nothing<br />
        Try<br />
            If SourceImage IsNot Nothing Then<br />
                If ShadowOpacity &lt; 0 Then<br />
                    ShadowOpacity = 0<br />
                ElseIf ShadowOpacity &gt; 255 Then<br />
                    ShadowOpacity = 255<br />
                End If<br />
                If ShadowSoftness &lt; 1 Then<br />
                    ShadowSoftness = 1<br />
                ElseIf ShadowSoftness &gt; 30 Then<br />
                    ShadowSoftness = 30<br />
                End If<br />
                If ShadowDistance &lt; 1 Then<br />
                    ShadowDistance = 1<br />
                ElseIf ShadowDistance &gt; 50 Then<br />
                    ShadowDistance = 50<br />
                End If<br />
                If ShadowColor = Color.Transparent Then<br />
                    ShadowColor = Color.Black<br />
                End If<br />
                If BackgroundColor = Color.Transparent Then<br />
                    BackgroundColor = Color.White<br />
                End If</p>
<p>                &#8216;get shadow<br />
                Dim shWidth As Integer = CInt(SourceImage.Width / ShadowSoftness)<br />
                Dim shHeight As Integer = CInt(SourceImage.Height / ShadowSoftness)<br />
                ImgShadow = New Bitmap(shWidth, shHeight)<br />
                g = Graphics.FromImage(ImgShadow)<br />
                g.Clear(Color.Transparent)<br />
                g.InterpolationMode = InterpolationMode.HighQualityBicubic<br />
                g.SmoothingMode = SmoothingMode.AntiAlias<br />
                Dim sre As Integer = 0<br />
                If ShadowRoundedEdges = True Then sre = 1<br />
                g.FillRectangle(New SolidBrush(Color.FromArgb(ShadowOpacity, ShadowColor)), _<br />
                                      sre, sre, shWidth, shHeight)<br />
                g.Dispose()</p>
<p>                &#8216;draw shadow<br />
                Dim d_shWidth As Integer = SourceImage.Width + ShadowDistance<br />
                Dim d_shHeight As Integer = SourceImage.Height + ShadowDistance<br />
                ImgTarget = New Bitmap(d_shWidth, d_shHeight)<br />
                g = Graphics.FromImage(ImgTarget)<br />
                g.Clear(BackgroundColor)<br />
                g.InterpolationMode = InterpolationMode.HighQualityBicubic<br />
                g.SmoothingMode = SmoothingMode.AntiAlias<br />
                g.DrawImage(ImgShadow, New Rectangle(0, 0, d_shWidth, d_shHeight), _<br />
                                        0, 0, ImgShadow.Width, ImgShadow.Height, GraphicsUnit.Pixel)<br />
                Select Case ShadowDirection<br />
                    Case ShadowDirections.BOTTOM_RIGHT<br />
                        g.DrawImage(SourceImage, _<br />
                            New Rectangle(0, 0, SourceImage.Width,SourceImage.Height), _<br />
                               0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.BOTTOM_LEFT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.RotateNoneFlipX)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                             New Rectangle(ShadowDistance, 0, SourceImage.Width, SourceImage.Height), _<br />
                                    0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.TOP_LEFT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.Rotate180FlipNone)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                                      New Rectangle(ShadowDistance, ShadowDistance, _<br />
                                                        SourceImage.Width, SourceImage.Height), _<br />
                                      0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.TOP_RIGHT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.RotateNoneFlipY)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                           New Rectangle(0, ShadowDistance, SourceImage.Width, SourceImage.Height), _<br />
                                  0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                End Select</p>
<p>                g.Dispose()<br />
                g = Nothing<br />
                ImgShadow.Dispose()<br />
                ImgShadow = Nothing</p>
<p>                SourceImage = New Bitmap(ImgTarget)<br />
                ImgTarget.Dispose()<br />
                ImgTarget = Nothing<br />
            End If</p>
<p>        Catch ex As Exception<br />
            If g IsNot Nothing Then<br />
                g.Dispose()<br />
                g = Nothing<br />
            End If<br />
            If ImgShadow IsNot Nothing Then<br />
                ImgShadow.Dispose()<br />
                ImgShadow = Nothing<br />
            End If<br />
            If ImgTarget IsNot Nothing Then<br />
                ImgTarget.Dispose()<br />
                ImgTarget = Nothing<br />
            End If<br />
        End Try</p>
<p>    End Sub<br />
[/sourcecode]</p>
<p>Besides, You can use this sub as in the following example (take a look at the comments&#8230;) :</p>
<p>[sourcecode language=&#8221;vb&#8221;]<br />
        Dim file_input As String = &quot;c:myfile.jpg&quot;<br />
        Dim file_output As String = &quot;c:myfilewithshadow.jpg&quot;</p>
<p>        &#8216;get bitmap&#8230;<br />
        Dim sourceImage As System.Drawing.Image = System.Drawing.Image.FromFile(file_input)<br />
        Dim format As System.Drawing.Imaging.ImageFormat = sourceImage.RawFormat<br />
        Dim bmpOut As System.Drawing.Bitmap = New Bitmap(sourceImage)</p>
<p>        &#8216;release any reference to the original file&#8230;<br />
        While sourceImage IsNot Nothing<br />
            sourceImage.Dispose()<br />
            sourceImage = Nothing<br />
        End While</p>
<p>        &#8216;drop black shadow on new bitmap with white background&#8230;<br />
        DropShadow(bmpOut, Color.Black, Color.White)</p>
<p>        &#8216;save file&#8230;<br />
        If bmpOut IsNot Nothing Then<br />
            bmpOut.Save(file_output, format)<br />
            bmpOut.Dispose()<br />
            bmpOut = Nothing<br />
        End If<br />
[/sourcecode]</p>
<p>PS:<br />
The subroutine executes only in &#8220;STAThread&#8221; so it&#8217;s thread-safe drawing.</p>
<p>Happy coding&#8230;</p>
<p>Max 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">72</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[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>]]></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>
]]></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[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>]]></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>
]]></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>How to implement IsNumeric() VB.NET function in C#</title>
		<link>https://www.maxvergelli.com/how-to-implement-isnumeric-vb-net-function-in-c-sharp/</link>
					<comments>https://www.maxvergelli.com/how-to-implement-isnumeric-vb-net-function-in-c-sharp/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 12 Jul 2019 14:30:42 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[String Manipulation Algorithms]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[numeric-conversion]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=47</guid>

					<description><![CDATA[This article describes how to implement the useful &#8220;IsNumeric&#8221; function in Microsoft Visual Basic .NET in Visual C#. The IsNumeric() function returns a Boolean value indicating whether an expression can be evaluated as a number. The IsNumeric() function returns True &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-implement-isnumeric-vb-net-function-in-c-sharp/" aria-label="How to implement IsNumeric() VB.NET function in C#">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>This article describes how to implement the useful &#8220;IsNumeric&#8221; function in Microsoft Visual Basic .NET in Visual C#. The IsNumeric() function returns a <em>Boolean</em> value indicating whether an expression can be evaluated as a number. The IsNumeric() function returns <em>True</em> when the data type of the expression is Short, Integer, Long, Decimal, Single or Double. Returns <em>True</em> if the expression is a string that can be converted to a Double. </p>
<p>Add the following code to your project:</p>
<p>[sourcecode language=&#8221;csharp&#8221;]<br />
// IsNumeric Function<br />
static bool IsNumeric(object Expression)<br />
{<br />
// Variable to collect the Return value of the TryParse method.<br />
	bool isNum;</p>
<p>// Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.<br />
	double retNum;</p>
<p>// The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.<br />
// The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.<br />
	isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );<br />
	return isNum;<br />
}<br />
[/sourcecode]</p>
<p>Have a nice day!</p>
<p>Max 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-implement-isnumeric-vb-net-function-in-c-sharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">47</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[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>]]></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>
]]></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[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>]]></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>
]]></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[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>]]></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>
]]></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[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>]]></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>
]]></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>
	</channel>
</rss>
