VB.NET | Suhail Kaleem - Part 2

VB.NET

Check String for Unicode Characters ( IsUnicode() )

1

in .Net All Strings are Unicode

we also know that  ASCII Characters range is up-to 255 any thing above 255 will be Unicode so what we will do is we will just check each character value if it is above 255 then there is Unicode Characters

here is function which does that

Public Shared Function IsUnicode(ByVal s As String) As Boolean

Dim items As Char() = s.ToCharArray()
For i As Integer = 0 To items.Length – 1

If CUShort(AscW(items(i))) > 255 Then
Return True
End If

Next

Return False

End Function

use it like

if IsUnicode(“لعربي“) then

‘ is unicode

else

‘not unicode

end if

Remove Diacritics from Arabic text ( Quran )

1

Remove this function to remove Diacritics from Arabic text

Private Shared Function RemoveDiacritics(ByVal stIn As String) As String
Dim stFormD As String = stIn.Normalize(NormalizationForm.FormD)
Dim sb As New StringBuilder()

For ich As Integer = 0 To stFormD.Length – 1
Dim uc As UnicodeCategory = CharUnicodeInfo.GetUnicodeCategory(stFormD(ich))
If uc <> UnicodeCategory.NonSpacingMark Then
sb.Append(stFormD(ich))
End If
Next

Return (sb.ToString().Normalize(NormalizationForm.FormC))
End Function

this code was convert to vb.net from c#

C# version code was taken from here :  http://blogs.msdn.com/michkap/archive/2007/05/14/2629747.aspx

Text : الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ

converted to : الحمد لله رب العالمين

How to set value for a Password field in ASP.NET 2.0

1

Recently i struggled a lot to set the value for the password field in my asp.net 2.0 application. In my application i generate the control dynamically based on data type of that field like checkbox for bit data type, textbox for string data type etc., But to my surprise we can’t set the text property of a Password Type field for security reasons. so i tried different ways to set the password field using javascript and hidden field. The problem in that approach is the user can go into view source and see it as clear text. After spending so many hours i came to find this solution which is very simple and elegant solution. we have to set the value as an attribute of the text box. The typical format for the same is.

txtPassword.Attributes.Add(“value”, PasswordValue)

Go to Top