Home > Software engineering >  Help: CDR eliminate vba dashed line source
Help: CDR eliminate vba dashed line source

Time:09-17

CDR often encountered in the paragraph is free at the end of the line, to delete, very troublesome, want to be a eliminate dashed line plug-in, who gave a train of thought, have the code better!

CodePudding user response:

Regular expressions to find replacement,

CodePudding user response:

 
Dim strTest As String
StrTest=strTest & amp; VbCrLf
StrTest=strTest & amp; "This is a test string, the front have a blank line" & amp; VbCrLf
StrTest=strTest & amp; VbCrLf
StrTest=strTest & amp; "In front of the line with a blank line" & amp; VbCrLf
StrTest=strTest & amp; "Behind this line has a number of blank lines" & amp; VbCrLf
StrTest=strTest & amp; VbCrLf
StrTest=strTest & amp; VbCrLf
StrTest=strTest & amp; VbCrLf
StrTest=strTest & amp; VbCrLf
StrTest=strTest & amp; "End, plus a carriage returns" & amp; VbCrLf

The Debug. Print "-- -- -- -- -- -- -- the original string"
The Debug. Print strTest
The Debug. Print "-- -- -- -- -- -- --"

'remove empty lines in the middle of the
Do
StrTest=Replace (strTest, vbCrLf & amp; VbCrLf, vbCrLf)
Loop While InStr (1, strTest, vbCrLf & amp; VbCrLf) & gt; 0

'remove head empty lines
If Left (strTest, 2)=vbCrLf Then strTest=Right (strTest, Len (strTest) - 2)

'to remove the rear carriage returns
If Right (strTest, 2)=vbCrLf Then strTest=Left (strTest, Len (strTest) - 2)

The Debug. Print "-- -- -- -- -- -- -- the results"
The Debug. Print strTest
The Debug. Print "-- -- -- -- -- -- --"

CodePudding user response:

 'remove empty lines in the middle of the 
Len1=Len (strTest)
Do
StrTest=Replace (strTest, vbCrLf & amp; VbCrLf, vbCrLf)
Len2=Len (strTest)
If len1=len2 then exit the do
Len1=len2
Loop

CodePudding user response:

Tested, no response, I was X4 version

CodePudding user response:

The above code is unreliable, according to my experience, some empty guild some blank characters and tabs, etc., the end may also be, in the human eyes seems to be "empty line"

 
'this code by " regular testing tools> v1.1.43 "generated automatically, please direct call TestReg process
Private Sub TestReg ()
Dim strData As String
Dim reg As Object
StrData="https://bbs.csdn.net/topics/1" & amp; VbCrLf & amp; _
"" & amp; VbCrLf & amp; _
"22" & amp; VbCrLf & amp; VbCrLf & amp; VbCrLf & amp; VbCrLf & amp; _
"423" & amp; VbCrLf & amp; VbCrLf & amp; _
"52"
The Set reg=CreateObject (" vbscript. RegExp ")
Reg. Global=True
Reg. The IgnoreCase=False
Reg. MultiLine=True
Reg. The Pattern="^ \ s *? The \ r \ n
"The Debug. Print reg. Replace (strData, "")
End Sub



And the building Lord whatever you x4 or x6, everyone can't be installed to test, to understand the CDR vba, although my computer ready-made x6, but also too lazy to understand,,
So you can understand the code and know how to achieve, and then change into your code, can not directly copy and paste can into the CDR can perform,

CodePudding user response:

Because the original poster is so in a word, also did not give a test case file, you can only guess the carriage returns,
Is that who knows a word behind empty line is caused by magical character,
  •  Tags:  
  • VBA
  • Related