Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am fetching data from a MS Word file into a text box in VB.Net and am displaying it paragraph by paragraph. It is working fine but the problem is that it is displaying even the empty spaces as paragraph.
Is there a way to eliminate the spaces so that only the text from the Word file is displayed in the text box ?

It is little urgent, can anyone please help me.

Thanks
Posted

The Christian's Amado answer is very good, but after your comments, i recomend you to read about String methods[^], especially: Substring[^], Replace[^] and many others.
You can see the old MS Visual Basic methods too: Left[^], Right[^], Mid[^].

For example, to replace Chr(13) with "" (empty string), use this:
VB
Dim sTmp as String = String.Empty
'inside the loop
sTmp = Trim(p.Range.Text)
sTmp.Replace(Chr(13),"")
 
Share this answer
 
Comments
Christian Amado 29-Aug-12 15:46pm    
Nice answer!
Maciej Los 29-Aug-12 15:48pm    
Thank you, Christian ;)
Christian Amado 29-Aug-12 15:49pm    
You're always welcome :)
For empty string use Trim() Method. This method removes all spaces in a particular string.

http://msdn.microsoft.com/en-us/library/t97s7bs3.aspx[^]

Hope it helps in any way.
 
Share this answer
 
v3
Comments
himanshu_88 29-Aug-12 11:35am    
will i be able to use trim() to delete all the spaces from an entire word document ?
Maciej Los 29-Aug-12 11:44am    
If you load data in a loop (thrue the collection of paragraphs), you need to cut spaces for each paragraph.
TextBox1.Text = TextBox1.Text + Trim(p.Range.text)
himanshu_88 29-Aug-12 12:10pm    
hi, i tried this code but it is not removing the spaces.
The empty spaces are still being shown on the text box as paragraphs.
Maciej Los 29-Aug-12 12:28pm    
Two reasons:
1) Trim deletes only starting and ending spaces. So, if you would like to delete spaces inside of text (between words) you need to iterate through the collection of signs in a text.
2) Each paragraph has (at the end of text) the sign: Chr(13)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900