Thursday, May 15, 2008

What is the % Code in My URL?

In order to prevent the misinterpretation of special characters such as a space, bracket (<>), or % in the URL (which stands for Uniform Resource Locator - it is the address you see in your browser's address bar indicating the location of the website you are visiting), browsers parse certain special characters using escape characters. This explains why when you click on a link such as: domain.com/page one.htm you see it parsed in the address bar as domain.com/page%20one.htm. In this case the %20 is the escape character for the space.
Common URL Escape Characters
Table of URL Escape Characters
Character Escape Character Character Escape Character
Space %20 # %23
$ %24 % %25
& %26 @ %40
' %60 / %2F
: %3A ; %3B
< %3C = %3D
> %3E ? %3F
[ %5B \ %5C
] %5D ^ %5E
{ %7B %7C
} %7D ~ %7E

SQL string split function

This can't be the best SQL string split function around, and it's the 3rd string split function I've borrowed to solve a problem. To stop spaghetti creep, I've got to choose one and go with it.I could pick one of the 3 string split functions I'm using, but maybe if I poll the community at large with a large pole I'll find some string split function out there that's better than sliced bread.
CREATE FUNCTION dbo.Split
( @RowData nvarchar(2000), @SplitOn nvarchar(5))
RETURNS @RtnValue table
( Id int identity(1,1), Data nvarchar(100))
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)

Begin
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))

Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return

END

Regular Expressions and C#, .NET

This Article explores the concept of Regular Expressions in the context of C#, .NET support for Regular
Expressions, Meta-characters and their Description, Character Escapes, Substitutions, Character Classes, Regular Expression Options and Atomic Zero-Width Assertions.

What are regular expressions?
Regular expressions are Patterns that can be used to match strings. You can call it a formula for matching strings that follow some pattern. Regular expression(s) can be considered as a Language, which is designed to manipulate text. You can then ask questions such as
“Does the given string match the pattern?”, or “Does the given string contain characters that match a pattern?”. Regular Expressions may be used to find one or more occurrences of a pattern of characters within a string. You may choose to replace it with some other characters or perform some other tasks based on the results obtained. These patterns of characters can be simple or very complex. Regular Expressions generally comprises of two types of characters –
1) Literal or Normal Characters such as “abcd123” 2) Special Characters that have a special meaning such as “.” Or “$” or “^”
Due to the special characters Regular Expressions form a very powerful means of manipulating strings and text.

.NET support for Regular Expressions:
.Net provides an extensive set of Regular expressions which you could use to create, modify or compare strings. They can be classified as follows –
a) Character Escapes b) Substitutions c) Character Classes d) Regular Expression Options e) Atomic Zero-Width Assertions f) Quantifiers g) Grouping Constructs h) Backreference Constructs i) Alternation Constructs j) Miscellaneous Constructs

Tuesday, March 25, 2008

Request Object Properties

The following table lists several properties of the Request object and displays values associated with your current real-time URL request for this page.
Request.UserAgent
The full identification of the browser requesting the page:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)


Request.Browser.Browser
The type of browser making the request:
IE
Request.Browser.Type
The type and major version of the browser making the request:
IE7
Request.Browser.Version
The major and minor versions of the browser request:
7
Request.Browser.MajorVersion
The major version of the browser making the request:
7
Request.Browser.MinorVersion
The minor version of the browser making the request:
0
Request.Browser.AOL
Whether this is an AOL browser:
FALSE
Request.Browser.Frames
Whether the browser supports frames:
TRUE
Request.Browser.JavaScript
Whether the browser supports JavaScript:
TRUE
Request.Browser.Platform
The type of operating system under which the browser is running:
WinXP
Request.IsSecureConnection
Whether the current connection uses a secure Web protocol:
FALSE
Request.UserHostAddress
The IP address from which the browser is requesting the page:
61.8.133.5
Server Properties->
Request.ServerVariables("LOCAL_ADDR")
The IP address of the server hosting the requested page.
168.16.190.175
Request.Url.Host
The URL of the server hosting the requested page:
msconline.maconstate.edu
Request.RawUrl
The portion of the URL request following the domain information:
/tutorials/ASPNET2/ASPNET03/aspnet03-07.aspx
Request.Url.Scheme
The type of URL request:
http
Request.Url.Port
The port through which the URL request is made:
80
Request.ApplicationPath
The virtual path to the root directory containing the page requested by the browser:
/Tutorials
Request.FilePath
The virtual path to the page requested by the browser:
/tutorials/ASPNET2/ASPNET03/aspnet03-07.aspx
Request.PhysicalApplicationPath
The physical path to the root directory of the page requested by the browser:
c:\Tutorials\
Request.PhysicalPath
The physical path to the page requested by the browser:
c:\Tutorials\ASPNET2\ASPNET03\aspnet03-07.aspx

How to get all HTTP Headers in ASP.NET

Drag and drop a literal onto your aspx web form in design view. The HTML will have this in it:

< id="Literal1" runat="server">
Now, in the code behind, add the following to the page load event:

'Put user code to initialize the page here
' Create a string variable to hold our server variables
Dim header As String
' Hold the values in a variable
Dim holder As String

' Iterate through the servervariables collection and put the headers and values in a variable
For Each header In Request.ServerVariables
' Store in our variable...
holder &= (header.ToString & " = " & Request.ServerVariables(header).ToString & " <> <>" & vbCrLf)
Next
' Put our variable into our literal to display on our page
Literal1.Text = holder

Run the page, and you'll get all the headers and values will be displayed.

Saturday, May 19, 2007

Slide show of images in HTML

/***********************************************
* Book Flip slideshow script- © Ger Versluis 2003
* Permission granted to DynamicDrive.com to feature script
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
/********************************************************
Create a div with transparent place holder in your html



width = 2*book image width +4 height = book image height+2
Insert onload in body tag

*********************************************************/
// 7 variables to control behavior
var Book_Image_Width=140;
var Book_Image_Height=225;
var Book_Border=true;
var Book_Border_Color="gray";
var Book_Speed=15;
var Book_NextPage_Delay=1500; //1 second=1000
var Book_Vertical_Turn=0;
// array to specify images and optional links. At least 4
// If Link is not needed keep it ""
Book_Image_Sources=new Array(
"images\\photo1.jpg","http://www.dynamicdrive.com",
"images\\photo2.jpg","http://www.javascriptkit.com",
"images\\photo3.jpg","", //this slide isn't linked
"images\\photo4.jpg","http://www.codingforums.com" // NOTE No comma after last line
);
/***************** DO NOT EDIT BELOW **********************************/
var B_LI,B_MI,B_RI,B_TI,B_Angle=0,B_CrImg=6,B_MaxW,B_Direction=1;
var B_MSz,B_Stppd=false;B_Pre_Img=new Array(Book_Image_Sources.length);
function ImageBook(){
if(document.getElementById){
for(i=0;i=Math.PI/2&&B_Direction){
B_Direction=0;
if(B_CrImg==Book_Image_Sources.length)B_CrImg=0;
B_MI.src=B_Pre_Img[B_CrImg].src;
B_MI.lnk=Book_Image_Sources[B_CrImg+1];
B_CrImg+=2}
if(B_Angle>=Math.PI){
B_Direction=1;
B_TI=B_LI;
B_LI=B_MI;
B_MI=B_TI;
if(Book_Vertical_Turn)B_MI.style.top=0+"px";
else B_MI.style.left=Book_Image_Width+1+"px";
B_MI.src=B_RI.src;
B_MI.lnk=B_RI.lnk;
setTimeout("Book_Next_Delay()",Book_NextPage_Delay)}
else setTimeout("BookImages()",50)}
else setTimeout("BookImages()",50)}
function Book_Next_Delay(){
if(B_CrImg==Book_Image_Sources.length)B_CrImg=0;
B_RI.src=B_Pre_Img[B_CrImg].src;
B_RI.lnk=Book_Image_Sources[B_CrImg+1];
B_MI.style.zIndex=2;
B_LI.style.zIndex=1;
B_Angle=0;
B_CrImg+=2;
setTimeout("BookImages()",50)}
function B_LdLnk(){if(this.lnk)window.location.href=this.lnk}
function B_Stp(){B_Stppd=true;this.style.cursor=this.lnk?"pointer":"default"}
function B_Rstrt(){B_Stppd=false}


Free DHTML scripts provided byDynamic Drive

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...