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.


///<summary> /// This converts the Binary array back to string. ///</summary> ///<param name="Binary"></param> ///<returns></returns> string BinaryUTF8ToString(byte[] Binary) { return System.Text.UnicodeEncoding.UTF8.GetString(Binary); } |
| stringConvertedString = BinaryUTF8ToString(ConvertStringEncoding( Request.Form["FormInput"], "windows-1256")); |
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).
C# public string ConvertDateCalendar(DateTime DateConv, string Calendar, string DateLangCulture) if (Calendar == "Hijri" && DateLangCulture.StartsWith("en-")) /// Set the date time format to the given culture - LAITH - 11/13/2005 1:04:22 PM - /// Set the calendar property of the date time format to the given calendar - LAITH - 11/13/2005 1:04:52 PM - /// We format the date structure to whatever we want - LAITH - 11/13/2005 1:05:39 PM - |
VB.Net |
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.
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.
The way it works is as follows:
You feed it with a string of letters: KeyLetters, a string of numbers: KeyNumbers, and how many characters you want the random key to be: Keychars. We then call Generate() which goes and generates a random number through the Randomize() statement and the Rnd() function.
Multiply Rnd() 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 >= o, we use it to get the value in the corresponding index in the character array.
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 Rnd() 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.
And so on, … the loop keeps "looping" while using, and we use a StringBuilder to construct our resulting string , until we've generated the desired number of characters for our Random Key. We convert the StringBuilder to String and return it with the function.
Note: XML comments in the source code were generated using "VBXC - VB.NET XML Commentor beta 3". I highly recommend it.
Module Module1 Dim KeyGen As RandomKeyGenerator ''' MODIFY THIS TO GET MORE KEYS - LAITH - 27/07/2005 22:48:30 -
OptionStrictOn ''' <date>27072005</date><time>071924</time> ''' <date>27072005</date><time>071924</time> ProtectedFriendWriteOnlyProperty KeyNumbers() AsString ''' <date>27072005</date><time>071924</time> ''' <date>27072005</date><time>072344</time> ''' CONVERT LettersArray & NumbersArray TO CHARACTR ARRAYS ''' IF THE VALUE IS AN EVEN NUMBER WE GENERATE A LETTER, ''' GENERATE A RANDOM INDEX IN THE NUMBERS |