<?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>intellisense &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/intellisense/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Tue, 07 Apr 2020 13:43:11 +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>intellisense &#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>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>
[sourcecode language=&#8221;vb&#8221;]
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]
[sourcecode language=&#8221;vb&#8221;]
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>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>
[sourcecode language=&#8221;vb&#8221;]
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>then, add a vb &#8220;code file&#8221; named &#8220;CultureCodeNames.vb&#8221; in &#8220;resources&#8221; folder with the following code</p>
[sourcecode language=&#8221;vb&#8221;]
<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>
[/sourcecode]
<p>Finally, add the last vb codefile &#8220;ResourceNames.vb&#8221; in &#8220;resources&#8221; folder with this code</p>
[sourcecode language=&#8221;vb&#8221;]
<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>
[/sourcecode]
<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>
[sourcecode language=&#8221;vb&#8221;]
<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>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>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>
[sourcecode language=&#8221;vb&#8221;]
&#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><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>
[sourcecode language=&#8221;vb&#8221;]
&#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]
]]></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>
