SIGN UP MEMBER LOGIN:    
ARTICLE

Space Remover Utility

Posted by Levent Camlibel Articles | Web Forms C# March 25, 2002
In this article, I want to show you how you can remove white spaces in a web page.
Reader Level:
Download Files:
 

Description:

In this article, I want to show you how you can remove white spaces in a web page. The reality is that you can remove white spaces in any text file such as html, asp, aspx, txt, and so forth. this application is useful if your web site has limited bandwidth. here is the code which removes white spaces.

public
void RemoveSpace()
{
char[] mychar=textBox1.Text.ToCharArray();
bFileSize=mychar.Length;
StringBuilder build=
new StringBuilder();
char prev=' ';
foreach(char ch in mychar)
{
if(ch=='\r' || ch=='\n' || ch=='\t')
{
}
else
{
if(prev==' ' && ch==' ')
{
}
else
{
build.Append(ch);
}
prev=ch;
}
}
textBox2.Text=build.ToString();
aFileSize=textBox2.Text.Length;
}

as you can see from the code above, we firstly eliminate the characters of tab, endofline, and then we check if there are more whitespaces between characters or not. if not, we append all these charaters to a variable of StringBuilder data type. anyway, during that, we eliminate all the spaces in the web page or any text file. I attached an example, it shows how you can use the application.

first thing is that, you need to open a web page from File menu--->Open---> File



in the following figure, we open Index.aspx to optimize, then click on Open button

when you click on Open button, the application reads text from choosen file and assign it to the textbox control. as you see in the following figure

now, it is time to click on Optimize button, as you see we save 17.35% from file size. so ,you will be able to server more visitors with the same bandwidth.

I hope it will be useful in your web programs. if you have any questions, do not hesitate to ask me.

Cheers!!

Login to add your contents and source code to this article
share this article :
post comment
 

thank for sending this artical

Posted by mukesh thakur Feb 03, 2009
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor