Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file
Delete empty spaces in a file Delete empty spaces in a file
Delete empty spaces in a file
Go Back  Xtreme Visual Basic Talk > > > Delete empty spaces in a file


Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2005, 11:52 PM
DeltaXFX DeltaXFX is offline
Newcomer
 
Join Date: Sep 2004
Posts: 12
Default


Delete empty spaces in a file

This is the closest thread i found to what i am looking for. i have a program that have a bunch of text boxes in it. when you print to file it puts the text in those boxes all on their own lines. i got that just fine using WriteLine.
the problem is some of my text boxes have to be multiline, so if the user makes a blank line in one of them after putting in text i get a blank line in my .txt file.
i tried
filecontents = Join(Split(filecontents, Environment.NewLine & Environment.NewLine), Environment.NewLine).Trim

but it doesnt seem to do anything.
i just set up a basic vb form with two text boxes and a button to test it.

when you click the button it reads the first text box into a string called "filecontents" then performs the operation above on it. then it fills out the second text box.
if i put:
test1

test2

test3
in the first text box, i get:
test1

test2

test3
back out.

i think if you can help me with that i can probably figure out my other question. but.. can you use the environment.newline to test for the number of linefeeds that are in a text box? for the program im doing, if i have say 5 lines in the text box i need to indent the last 4 lines. so can i test for the lines and then put padding in it?
thanks!

Last edited by Shurik12; 01-26-2005 at 07:10 AM.
Reply With Quote
  #2  
Old 01-26-2005, 07:05 AM
wayneph's Avatar
waynephDelete empty spaces in a file wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

The easiest thing would probably be to use the Replace method. Anytime you have a Line Break, replace it with a Line Break and a Tab.

MSDN Replace Method

By the way - Instead of pulling up an old thread you should probably start your own for a new question. You can reference an old one by putting a link to it if you need to.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 01-26-2005, 04:46 PM
MKoslof's Avatar
MKoslofDelete empty spaces in a file MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Or build an arraylist, splitting the text at each new line. If the line is empty, disregard it or don't include it in the Arraylist index. Then each clean line can be modified (or modified before reading it into the arraylist to have only a line break or tab, etc.) Then, you have only formatted text data an no empty lines. If you show us your code, we can provide the best advice regarding the current situation .
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #4  
Old 01-26-2005, 11:59 PM
DeltaXFX DeltaXFX is offline
Newcomer
 
Join Date: Sep 2004
Posts: 12
Default

Awesome! The replace method is exactly what I needed. My bad about not posting to a new thread.
The code is at home, I should have brought it here. But I have a single form with 4 tabs, each tab has about 10 text boxes on it. The are only 3 or 4 text boxes in the whole form that are going to be multiline. I have the text boxes from each tab save into an array. like page1(9), page2(9)... I save each text box to an element of the array. Then i just use a stream writer and For Loop to write the strings in all the arrays out to a text file.
I still have a questions about this:

filecontents = Join(Split(filecontents, Environment.NewLine & Environment.NewLine), Environment.NewLine).Trim

I finally got it to work right, must have screwed up somewhere, but why do you need the "env.newline & env.newline" in the split?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file Delete empty spaces in a file
Delete empty spaces in a file
Delete empty spaces in a file
 
Delete empty spaces in a file
Delete empty spaces in a file
 
-->