﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Laith Zraikat: .Net Development</title><link>http://laithz.jeeran.com/categories/.Net_Development/</link><description>I Innovate, Therefore I Am.</description><pubDate>Sat, 21 Jun 2008 17:06:26 GMT</pubDate><copyright>Copyright 2008 Laith</copyright><generator>jeeran RSSGenerator v1.0</generator><image><url>http://laithz.jeeran.com/photos/profile_t.jpg</url><title>Laith Zraikat: .Net_Development</title><link>http://laithz.jeeran.com/categories/.Net_Development/</link></image><item><title>Jeeran in Venture Magazine</title><link>http://laithz.jeeran.com/archive/2006/6/65027.html</link><guid isPermaLink="false">65027</guid><description>&lt;span style="font-size: 18pt; font-weight: bold;"&gt;Venture&lt;/span&gt; is a new Jordanian business magazine. It is by the same creative people behind JO Magazine. The content and style seem very promising, and it stands to achieve the same outstanding sucess witnesses by its sister "JO".&lt;br /&gt;&lt;br /&gt;This is an interview we did with Venture magazine in its June issue. To Qais, Jibril ,and the rest of the team; Thanks guys, we really enjoyed it.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.airlinetycoons.com/Jeeran_Venture.jpg" target="_self" title="Click to View"&gt;&lt;img src="http://www.airlinetycoons.com/t_2_Jeeran_Venture.jpg" alt="" align="" /&gt;&lt;/a&gt;&lt;br /&gt;</description><pubDate>Thu, 29 Jun 2006 18:58:00 GMT</pubDate><comments>http://laithz.jeeran.com/archive/2006/6/65027.html#comments</comments><author>Laith&lt;laithz@jeeran.com&gt;</author><category domain="http://laithz.jeeran.com/categories/.Net_Development/">.Net Development</category></item><item><title>ASP.Net 2.0 &amp;quot;How to&amp;quot; Videos</title><link>http://laithz.jeeran.com/archive/2006/2/51428.html</link><guid isPermaLink="false">51428</guid><description>Recently released video lessons on the common questions about the new features in ASP.Net 2.0. They will provide clear, easy, and straight to the point examples on how to perform some advanced functions. They are great for all levels, newbie to expert.&lt;br /&gt;&lt;br /&gt;The topics covered:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Caching (2 parts)&lt;/li&gt;&lt;li&gt;Create a full-featured customer login protal&lt;/li&gt;&lt;li&gt;Data: create data driven web sites&lt;/li&gt;&lt;li&gt;Form Building&lt;/li&gt;&lt;li&gt;Localization&lt;/li&gt;&lt;li&gt;Master Pages and Site Navigation&lt;/li&gt;&lt;li&gt;Membership and Roles&lt;/li&gt;&lt;li&gt;Profiles and Themes&lt;/li&gt;&lt;li&gt;Web Parts and Personalization&lt;/li&gt;&lt;li&gt;Tips and Tricks: covers a wide range of techniques for enhancing ASP.Net web pages.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;For a more detailed description and download links, read:&lt;br /&gt;&lt;a href="http://blogs.msdn.com/bgold/archive/2006/02/20/535869.aspx" target="_blank"&gt;ASP.NET 2.0 How Do I Video Series is here -- a must see&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;</description><pubDate>Sat, 25 Feb 2006 15:00:00 GMT</pubDate><comments>http://laithz.jeeran.com/archive/2006/2/51428.html#comments</comments><author>Laith&lt;laithz@jeeran.com&gt;</author><category domain="http://laithz.jeeran.com/categories/.Net_Development/">.Net Development</category><category domain="http://laithz.jeeran.com/categories/Web_Development/">Web Development</category></item><item><title>Converting a string from UTF-8 to Windows-1256 encoding</title><link>http://laithz.jeeran.com/archive/2005/12/51409.html</link><guid isPermaLink="false">51409</guid><description>I recently was faced with a problem where a form was sending text encoded in UTF-8, and the ASP.Net page processing the data used "windows-1256". This really messed up the text.&lt;br /&gt;&lt;br /&gt;The dilemma I was that I had to keep the page encoding containing the form as utf-8, and I had to keep the processing page as windows-1256. &lt;br /&gt;&lt;br /&gt;I was able to solve it by converting the incoming text from utf-8 to windows-1256 by using the following two methods: &lt;br /&gt;&lt;br /&gt;&lt;table style="background: rgb(220, 220, 220) url(undefined) repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 0); width: 95%;" align="center" cellpadding="5" width=""&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt; Converts any UTF-8 string into the selected character set&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt; ///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;param name="StringToConvert"&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;param name="TargetCharSet"&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 10pt; font-family: Courier;"&gt;public &lt;span style="color: blue;"&gt;byte&lt;/span&gt;[] ConvertUTF8StringEncoding(&lt;span style="color: blue;"&gt;string&lt;/span&gt; StringToConvert, &lt;span style="color: blue;"&gt;string&lt;/span&gt; TargetCharSet)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt;byte&lt;/span&gt;[] ByteConvertedString;&lt;br /&gt;&lt;span style="color: blue;"&gt;byte&lt;/span&gt;[] ByteStringToConvert;&lt;br /&gt;&lt;span style="color: teal;"&gt;Encoding&lt;/span&gt; TargetEncoding;&lt;br /&gt;&lt;span style="color: forestgreen;"&gt;// Convert the string to a Byte array&lt;/span&gt;&lt;br /&gt;ByteStringToConvert = &lt;span style="color: teal;"&gt;Encoding&lt;/span&gt;.UTF8.GetBytes(StringToConvert);&lt;br /&gt;&lt;span style="color: forestgreen;"&gt;// Get the target encoding type&lt;/span&gt;&lt;br /&gt;TargetEncoding = &lt;span style="color: teal;"&gt;Encoding&lt;/span&gt;.GetEncoding(TargetCharSet);&lt;br /&gt;&lt;span style="color: forestgreen;"&gt;// Convert the byte array using the target encoding&lt;/span&gt;&lt;br /&gt;ByteConvertedString = &lt;span style="color: teal;"&gt;Encoding&lt;/span&gt;.Convert(System.Text.&lt;span style="color: teal;"&gt;Encoding&lt;/span&gt;.UTF8, TargetEncoding, ByteStringToConvert);&lt;br /&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt; ByteConvertedString;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt; This converts the Binary array back to string.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;/summary&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;param name="Binary"&amp;gt;&amp;lt;/param&amp;gt;&lt;br /&gt;///&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: green;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: gray;"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Courier;"&gt;string BinaryUTF8ToString(&lt;span style="color: blue;"&gt;byte&lt;/span&gt;[] Binary)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt; System.Text.&lt;span style="color: teal;"&gt;UnicodeEncoding&lt;/span&gt;.UTF8.GetString(Binary);&lt;br /&gt;}&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-size: 12pt;" times="" new="" roman="" ;=""&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;The first method will return a byte array of the string encoded in windows-1256. The second method will convert the binary array back to its string value. &lt;br /&gt;&lt;br /&gt;So to convert any UTF-8 form input string, we write the following &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;table style="background: rgb(220, 220, 220) url(undefined) repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 0); width: 95%;" align="center" cellpadding="5" width=""&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: blue;"&gt;string&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Times New Roman&amp;quot;;"&gt;ConvertedString = &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Courier;"&gt;BinaryUTF8ToString(ConvertStringEncoding(&lt;br /&gt;Request.Form[&lt;span style="color: maroon; font-size: 10pt;"&gt;"FormInput"&lt;/span&gt;], &lt;span style="color: maroon; font-size: 10pt;"&gt;"windows-1256"&lt;/span&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-size: 12pt;" times="" new="" roman="" ;=""&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;</description><pubDate>Thu, 22 Dec 2005 20:29:00 GMT</pubDate><comments>http://laithz.jeeran.com/archive/2005/12/51409.html#comments</comments><author>Laith&lt;laithz@jeeran.com&gt;</author><category domain="http://laithz.jeeran.com/categories/.Net_Development/">.Net Development</category></item><item><title>Converting a date from Gregorian calendar to Hijri</title><link>http://laithz.jeeran.com/archive/2005/11/51399.html</link><guid isPermaLink="false">51399</guid><description>&lt;p style="text-align: left; direction: ltr; unicode-bidi: embed;" class="MsoNormal"&gt;This piece of code will take the date you give it, and convert it to its equivilant under the Hijri or Gregorian calendar according to your arguments. It will also enable you to set the language in which you wish to display the Gregorian dates (Hijri date will always be displayd in arabic).&lt;span style="font-size: 10pt;" courier="" new="" ;="" color="" blue=""&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;table style="background: rgb(220, 220, 220) url(undefined) repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 0); width: 95%;" align="center" cellpadding="5" width=""&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span 8pt="" font-size="" ;="" new="" courier="" style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;p style="text-align: left; direction: ltr; unicode-bidi: embed;" class="MsoNormal"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style="font-weight: bold; font-size: 10pt;"&gt;C#&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;" dir="ltr"&gt;&lt;span style="font-size: 8pt;"&gt;public &lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; ConvertDateCalendar(&lt;span style="color: rgb(0, 128, 128);"&gt;DateTime&lt;/span&gt; DateConv, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Calendar, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; DateLangCulture)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;DateTimeFormatInfo&lt;/span&gt; DTFormat;&lt;br /&gt;DateLangCulture = DateLangCulture.ToLower();&lt;br /&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;///&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; We can't have the hijri date writen in English. We will get a runtime error - LAITH - 11/13/2005 1:01:45 PM -&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;" dir="ltr"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (Calendar == &lt;span style="color: rgb(128, 0, 0);"&gt;"Hijri"&lt;/span&gt; &amp;amp;&amp;amp; DateLangCulture.StartsWith(&lt;span style="color: rgb(128, 0, 0);"&gt;"en-"&lt;/span&gt;))&lt;br /&gt;{&lt;br /&gt;DateLangCulture = &lt;span style="color: rgb(128, 0, 0);"&gt;"ar-sa"&lt;/span&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;" dir="ltr"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;///&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; Set the date time format to the given culture - LAITH - 11/13/2005 1:04:22 PM -&lt;/span&gt;&lt;br /&gt;DTFormat = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; System.Globalization.&lt;span style="color: rgb(0, 128, 128);"&gt;CultureInfo&lt;/span&gt;(DateLangCulture, &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;).DateTimeFormat;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;" dir="ltr"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;///&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; Set the calendar property of the date time format to the given calendar - LAITH - 11/13/2005 1:04:52 PM -&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;switch&lt;/span&gt; (Calendar)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;case&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"Hijri"&lt;/span&gt;:&lt;br /&gt;DTFormat.Calendar = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; System.Globalization.&lt;span style="color: rgb(0, 128, 128);"&gt;HijriCalendar&lt;/span&gt;();&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;case&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;"Gregorian"&lt;/span&gt;:&lt;br /&gt;DTFormat.Calendar = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; System.Globalization.&lt;span style="color: rgb(0, 128, 128);"&gt;GregorianCalendar&lt;/span&gt;();&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;default&lt;/span&gt;:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;""&lt;/span&gt;;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;" dir="ltr"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;///&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; We format the date structure to whatever we want - LAITH - 11/13/2005 1:05:39 PM -&lt;/span&gt;&lt;br /&gt;DTFormat.ShortDatePattern = &lt;span style="color: rgb(128, 0, 0);"&gt;"dd/MM/yyyy"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; (DateConv.Date.ToString(&lt;span style="color: rgb(128, 0, 0);"&gt;"f"&lt;/span&gt;, DTFormat));&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description><pubDate>Wed, 30 Nov 2005 16:18:00 GMT</pubDate><comments>http://laithz.jeeran.com/archive/2005/11/51399.html#comments</comments><author>Laith&lt;laithz@jeeran.com&gt;</author><category domain="http://laithz.jeeran.com/categories/.Net_Development/">.Net Development</category></item><item><title>Strip HTML tags from a string in .NET</title><link>http://laithz.jeeran.com/archive/2005/11/51393.html</link><guid isPermaLink="false">51393</guid><description>The best and shortest way is to use Regular Expression for this task: &lt;br /&gt;&lt;br /&gt;&lt;table style="background: rgb(220, 220, 220) url(undefined) repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 0); width: 95%;" align="center" cellpadding="5" width=""&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;p class="MsoNormal" style="direction: ltr; unicode-bidi: embed; text-align: left;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style="font-weight: bold; font-size: 10pt;"&gt;VB.Net&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Function&lt;/span&gt; StripHTMLTags(&lt;span style="color: blue; font-size: 8pt;"&gt;ByVal&lt;/span&gt; HTMLToStrip &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;) &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; stripped &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;If&lt;/span&gt; HTMLToStrip &amp;lt;&amp;gt; "" &lt;span style="color: blue; font-size: 8pt;"&gt;Then&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;stripped = Regex.Replace(HTMLToStrip, "&amp;lt;(.|\n)+?&amp;gt;", &lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;.Empty)&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Return&lt;/span&gt; stripped&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Return&lt;/span&gt; ""&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 8pt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-weight: bold; font-size: 10pt;"&gt;C#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 8pt;"&gt;private&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;string&lt;/span&gt; StripHTMLTags(&lt;span style="color: blue; font-size: 8pt;"&gt;string&lt;/span&gt; HTMLToStrip)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;string&lt;/span&gt; stripped;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;if&lt;/span&gt; (!&lt;span style="color: teal; font-size: 8pt;"&gt;Convert&lt;/span&gt;.ToBoolean(HTMLToStrip == &lt;span style="color: maroon; font-size: 8pt;"&gt;""&lt;/span&gt;))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;stripped = &lt;span style="color: teal; font-size: 8pt;"&gt;Regex&lt;/span&gt;.Replace(formHTML.Text, &lt;span style="color: maroon; font-size: 8pt;"&gt;@"&amp;lt;(.|\n)*?&amp;gt;"&lt;/span&gt;, &lt;span style="color: blue; font-size: 8pt;"&gt;string&lt;/span&gt;.Empty);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;return&lt;/span&gt; stripped;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;{&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;return&lt;/span&gt;&lt;span style="color: maroon; font-size: 8pt;"&gt;""&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 dir="ltr"&gt;&lt;span style="font-size: 12pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h2&gt;</description><pubDate>Tue, 22 Nov 2005 21:28:00 GMT</pubDate><comments>http://laithz.jeeran.com/archive/2005/11/51393.html#comments</comments><author>Laith&lt;laithz@jeeran.com&gt;</author><category domain="http://laithz.jeeran.com/categories/.Net_Development/">.Net Development</category></item><item><title>Generate a Random String Key in VB.NET</title><link>http://laithz.jeeran.com/archive/2005/11/51382.html</link><guid isPermaLink="false">51382</guid><description>&lt;h2 dir="ltr"&gt;Introduction&lt;/h2&gt;&lt;p dir="ltr"&gt;I had to create a piece of code that will give me a set of randomly generated keys. Each key had to consist of letters and numbers, and the letters could be either (randomly) lowercase or uppercase.&lt;/p&gt;&lt;p dir="ltr"&gt;Looking at some sample code on the web, I could not find what I needed. All the examples I found either generated numbers only, or letters only. I also wanted this random key to be based on a certain rule that made it "not straightforward" random, so, I came up with this little piece of code.&lt;/p&gt;&lt;h2 dir="ltr"&gt;Using the code&lt;/h2&gt;&lt;p dir="ltr"&gt;The way it works is as follows:&lt;/p&gt;&lt;p dir="ltr"&gt;You feed it with a string of letters: &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;KeyLetters&lt;/span&gt;&lt;/code&gt;, a string of numbers: &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;KeyNumbers&lt;/span&gt;&lt;/code&gt;, and how many characters you want the random key to be: &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;Keychars&lt;/span&gt;&lt;/code&gt;. We then call &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;Generate()&lt;/span&gt;&lt;/code&gt; which goes and generates a random number through the &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;Randomize()&lt;/span&gt;&lt;/code&gt; statement and the &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;Rnd()&lt;/span&gt;&lt;/code&gt; function.&lt;/p&gt;&lt;p dir="ltr"&gt;Multiply &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;Rnd()&lt;/span&gt;&lt;/code&gt; by 111 -could be any number we choose which is sufficient enough to bring the value above zero. If the resulting number is an even number, then our random character will be a letter. If we get an odd number, then our random character will be a number. To generate a random character, we generate a random index for one of the character arrays (depending on what our random character will be). Once we have an index which is &amp;gt;= o, we use it to get the value in the corresponding index in the character array.&lt;/p&gt;&lt;p dir="ltr"&gt;If we are generating a number, then that is our random character. If we are generating a letter, then we need to determine whether we want it uppercase or lowercase. For that purpose we generate another random number by multiplying the value of &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;Rnd()&lt;/span&gt;&lt;/code&gt; by 99 – could be any other number too – and then determine whether the result is even or odd. This time, we capitalize the letter if we get an odd number, otherwise we leave it as it is.&lt;/p&gt;&lt;p dir="ltr"&gt;And so on, … the loop keeps "looping" while using, and we use a &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;StringBuilder&lt;/span&gt;&lt;/code&gt; to construct our resulting string , until we've generated the desired number of characters for our Random Key. We convert the &lt;code&gt;&lt;span style="font-size: 10pt;"&gt;StringBuilder&lt;/span&gt;&lt;/code&gt; to &lt;span class="vb-keyword"&gt;&lt;span ,new="" courier="" style="font-size: 10pt;"&gt;String&lt;/span&gt;&lt;/span&gt; and return it with the function.&lt;/p&gt;&lt;p dir="ltr"&gt;Note: XML comments in the source code were generated using "VBXC - VB.NET XML Commentor beta 3". I highly recommend it.&lt;/p&gt;&lt;h4 dir="ltr"&gt;&lt;table style="background: rgb(220, 220, 220) url(undefined) repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(0, 0, 0); width: 95%;" align="center" cellpadding="5" width=""&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;&lt;span style="font-size: 8pt;"&gt;Module Module1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Sub&lt;/span&gt;&lt;st1:place w:st="on"&gt;Main&lt;/st1:place&gt;()&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New; font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; KeyGen &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt; RandomKeyGenerator&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; NumKeys &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; i_Keys &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; RandomKey &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New; font-size: 8pt;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' MODIFY THIS TO GET MORE KEYS - LAITH - 27/07/2005 22:48:30 -&lt;/span&gt;&lt;br /&gt;NumKeys = 20&lt;br /&gt;KeyGen = &lt;span style="color: blue; font-size: 8pt;"&gt;New&lt;/span&gt; RandomKeyGenerator&lt;br /&gt;KeyGen.KeyLetters = "abcdefghijklmnopqrstuvwxyz"&lt;br /&gt;KeyGen.KeyNumbers = "0123456789"&lt;br /&gt;KeyGen.KeyChars = 12&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;For&lt;/span&gt; i_Keys = 1 &lt;span style="color: blue; font-size: 8pt;"&gt;To&lt;/span&gt; NumKeys&lt;br /&gt;RandomKey = KeyGen.Generate()&lt;br /&gt;Console.WriteLine(RandomKey)&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Next&lt;/span&gt;&lt;br /&gt;Console.WriteLine("Press any key to exit...")&lt;br /&gt;Console.Read()&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 8pt;"&gt;Sub&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;End Module&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-weight: bold; font-size: 8pt;"&gt;&lt;br /&gt;RandomKeyGenerator.vb&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; color: blue; font-size: 8pt;"&gt;Option&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Strict&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;On&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier; font-size: 8pt;"&gt;Imports System.Text&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New; color: rgb(0, 128, 0);"&gt;''' &amp;lt;date&amp;gt;27072005&amp;lt;/date&amp;gt;&amp;lt;time&amp;gt;070339&amp;lt;/time&amp;gt;&lt;br /&gt;''' &amp;lt;type&amp;gt;class&amp;lt;/type&amp;gt;&lt;br /&gt;''' &amp;lt;summary&amp;gt;&lt;br /&gt;''' REQUIRES PROPERTIES: KeyLetters, KeyNumbers, MaxChars&lt;br /&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier; font-size: 8pt;"&gt;Public &lt;span style="color: blue; font-size: 8pt;"&gt;Class&lt;/span&gt; RandomKeyGenerator&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; Key_Letters &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; Key_Numbers &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; Key_Chars &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; LettersArray &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Char&lt;/span&gt;()&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; NumbersArray &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Char&lt;/span&gt;()&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;date&amp;gt;27072005&amp;lt;/date&amp;gt;&amp;lt;time&amp;gt;071924&amp;lt;/time&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;type&amp;gt;property&amp;lt;/type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' WRITE ONLY PROPERTY. HAS TO BE SET BEFORE CALLING GENERATE()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Protected&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Friend&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;WriteOnly&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Property&lt;/span&gt; KeyLetters() &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Set&lt;/span&gt;(&lt;span style="color: blue; font-size: 8pt;"&gt;ByVal&lt;/span&gt; Value &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;)&lt;br /&gt;Key_Letters = Value&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Set&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;&lt;span style="font-size: 8pt;"&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;date&amp;gt;27072005&amp;lt;/date&amp;gt;&amp;lt;time&amp;gt;071924&amp;lt;/time&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;type&amp;gt;property&amp;lt;/type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' WRITE ONLY PROPERTY. HAS TO BE SET BEFORE CALLING GENERATE()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New; font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Protected&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Friend&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;WriteOnly&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Property&lt;/span&gt; KeyNumbers() &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Set&lt;/span&gt;(&lt;span style="color: blue; font-size: 8pt;"&gt;ByVal&lt;/span&gt; Value &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;)&lt;br /&gt;Key_Numbers = Value&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Set&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;date&amp;gt;27072005&amp;lt;/date&amp;gt;&amp;lt;time&amp;gt;071924&amp;lt;/time&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;type&amp;gt;property&amp;lt;/type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' WRITE ONLY PROPERTY. HAS TO BE SET BEFORE CALLING GENERATE()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Protected&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Friend&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;WriteOnly&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Property&lt;/span&gt; KeyChars() &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Set&lt;/span&gt;(&lt;span style="color: blue; font-size: 8pt;"&gt;ByVal&lt;/span&gt; Value &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;)&lt;br /&gt;Key_Chars = Value&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Set&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;date&amp;gt;27072005&amp;lt;/date&amp;gt;&amp;lt;time&amp;gt;072344&amp;lt;/time&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;type&amp;gt;function&amp;lt;/type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' GENERATES A RANDOM STRING OF LETTERS AND NUMBERS.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' LETTERS CAN BE RANDOMLY CAPITAL OR SMALL.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' &amp;lt;returns type="String"&amp;gt;RETURNS THE RANDOMLY GENERATED KEY&amp;lt;/returns&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Function&lt;/span&gt; Generate() &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; i_key &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; Random1 &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Single&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; arrIndex &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt; Int16&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; sb &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;New&lt;/span&gt; StringBuilder&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Dim&lt;/span&gt; RandomLetter &lt;span style="color: blue; font-size: 8pt;"&gt;As&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: Courier; font-size: 8pt;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' CONVERT LettersArray &amp;amp; NumbersArray TO CHARACTR ARRAYS&lt;/span&gt;&lt;br /&gt;LettersArray = Key_Letters.ToCharArray&lt;br /&gt;NumbersArray = Key_Numbers.ToCharArray&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;For&lt;/span&gt; i_key = 1 &lt;span style="color: blue; font-size: 8pt;"&gt;To&lt;/span&gt; Key_Chars&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' START THE CLOCK - LAITH - 27/07/2005 18:01:18 -&lt;/span&gt;&lt;br /&gt;Randomize()&lt;br /&gt;Random1 = Rnd()&lt;br /&gt;arrIndex = -1&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New; font-size: 8pt;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' IF THE VALUE IS AN EVEN NUMBER WE GENERATE A LETTER,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' OTHERWISE WE GENERATE A NUMBER&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' - LAITH - 27/07/2005 18:02:55 -&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' THE NUMBER '111' WAS RANDOMLY CHOSEN. ANY NUMBER&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' WILL DO, WE JUST NEED TO BRING THE VALUE&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' ABOVE '0' - LAITH - 27/07/2005 18:40:48 -&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;If&lt;/span&gt; (&lt;span style="color: blue; font-size: 8pt;"&gt;CType&lt;/span&gt;(Random1 * 111, &lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;)) &lt;span style="color: blue; font-size: 8pt;"&gt;Mod&lt;/span&gt; 2 = 0 &lt;span style="color: blue; font-size: 8pt;"&gt;Then&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' GENERATE A RANDOM INDEX IN THE LETTERS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' CHARACTER ARRAY - LAITH - 27/07/2005 18:47:44 -&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Do&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;While&lt;/span&gt; arrIndex &amp;lt; 0&lt;br /&gt;arrIndex = _ Convert.ToInt16(LettersArray.GetUpperBound(0) _&lt;br /&gt;* Random1)&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Loop&lt;br /&gt;&lt;/span&gt; RandomLetter = LettersArray(arrIndex)&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' CREATE ANOTHER RANDOM NUMBER. IF IT IS ODD,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' WE CAPITALIZE THE LETTER&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' - LAITH - 27/07/2005 18:55:59 -&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;If&lt;/span&gt; (&lt;span style="color: blue; font-size: 8pt;"&gt;CType&lt;/span&gt;(arrIndex * Random1 * 99, &lt;span style="color: blue; font-size: 8pt;"&gt;Integer&lt;/span&gt;)) &lt;span style="color: blue; font-size: 8pt;"&gt;Mod&lt;/span&gt; 2 &amp;lt;&amp;gt; 0 &lt;span style="color: blue; font-size: 8pt;"&gt;Then&lt;/span&gt;&lt;br /&gt;RandomLetter = LettersArray(arrIndex).ToString&lt;br /&gt;RandomLetter = RandomLetter.ToUpper&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;If&lt;/span&gt;&lt;br /&gt;sb.Append(RandomLetter)&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="text-align: left; direction: ltr; unicode-bidi: embed;"&gt;&lt;span style="font-size: 8pt;"&gt;&lt;span style="font-family: &amp;quot;Courier&amp;quot;,New; font-size: 8pt;"&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' GENERATE A RANDOM INDEX IN THE NUMBERS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: green; font-size: 8pt;"&gt;''' CHARACTER ARRAY - LAITH - 27/07/2005 18:47:44 -&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Do&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;While&lt;/span&gt; arrIndex &amp;lt; 0&lt;br /&gt;arrIndex = _ Convert.ToInt16(NumbersArray.GetUpperBound(0) _&lt;br /&gt;* Random1)&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Loop&lt;/span&gt;&lt;br /&gt;sb.Append(NumbersArray(arrIndex))&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Next&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Return&lt;/span&gt; sb.ToString&lt;br /&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;End&lt;/span&gt;&lt;span style="color: blue; font-size: 8pt;"&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Courier; font-size: 8pt;"&gt;End &lt;span style="color: blue; font-size: 8pt;"&gt;Class&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span style="font-size: 12pt;"&gt;Source Code:&lt;/span&gt;&lt;/h4&gt;&lt;a href="http://www.codeproject.com/vb/net/RandomKey/RandomKey_demo.zip"&gt;Download demo project - 2.36 Kb&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/vb/net/RandomKey/RandomKey_project.zip"&gt;Download source - 7.64 Kb&lt;/a&gt;</description><pubDate>Mon, 21 Nov 2005 20:48:00 GMT</pubDate><comments>http://laithz.jeeran.com/archive/2005/11/51382.html#comments</comments><author>Laith&lt;laithz@jeeran.com&gt;</author><category domain="http://laithz.jeeran.com/categories/.Net_Development/">.Net Development</category></item></channel></rss>