Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Erasing blank lines from strings 1

Status
Not open for further replies.

Shabal

IS-IT--Management
Jun 30, 2006
5
CA
Hi everyone

If I have a multi-line string like the following:

''blablabla bla
blabla


blabla

blablabla''

Is there a way I can erase all the blank lines from the string to either generate a new string or modify the existing one? The solution I'm looking for must work for all possible array sizes and any number of blank lines.

I'd really appreciate your help.

Thanks
Shabal
 
Could help if you bothered to mention what application you are talking about.

So, is this text in an Outlook message?

String in an Access field?

Text in a cell in Excel?

Some text in a Word document?

Text in a texbox on a Powerpoint slide?

Hmmmmm?

If it is text in a Word document, then it is likely very easy to do what you ask.
must work for all possible array sizes and any number of blank lines
Let's see, the blank lines I understand, but umm, WHAT array?

Again, if this is Word, and those blank lines are paragraph marks, then it woukd be a piece of cake to get rid of them.

But, shrug, since I have no idea....

faq219-2884

Gerry
My paintings and sculpture
 
Hi fumei,

The application I was talking about is indeed Word and "array" is a typo, it should be "string" - sorry for the confusion.

What'd I'd like to do is copy the text of an open Word Doc into a string (myText = ActiveDocument.Content.Text) and then replace, in the string, all instances of two or more consecutive paragraph marks with one (leaving the document unchanged).

Thanks
Shabal
 
So, you have a string with linefeeds. You could split the string into an array:
strArray = split(myText,chr(10))
Now you have an array, some of whose elements are blank. You can filter the array to remove those:
strArray = filter(strArray,"",False)
Now you can join the filtered array back into a string:
myText = join(strArray,chr(10)

_________________
Bob Rashkin
 




You could turn on your macro recorder and record replacing ^p^p with^p and observe your code.

Skip,

[glasses] [red][/red]
[tongue]
 
Skip, the OP wants leaving the document unchanged
 
Code:
Dim strMyString As String
Dim oPara As Word.Paragraph
   For Each oPara In ActiveDocument.Paragraphs
      If oPara.Range.Text <> Chr(13) Then
         strMyString = strMyString & _
            oPara.Range.Text
      End If
   Next
MsgBox strMyString
blablabla bla
blabla


blabla

blablabla


will return:

blablabla bla
blabla
blabla
blablabla

If indeed those are paragraph marks between them.


faq219-2884

Gerry
My paintings and sculpture
 
Great, it works! Thanks everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top