Home > Software engineering >  How to delete the specified string in the WORD?
How to delete the specified string in the WORD?

Time:09-15

Participant list
today to attend have
Yishan zhang
Zhang Ershan
Zhang SAN hill
Zhang Sishan
Zhang Wushan


Participant list
tomorrow to attend a
X.h.
Da-hu wang
There are other guests around,,,,


Participant list
the day after tomorrow to attend the
Doubleli
Lee also
Plum


Cut out all of the scarlet letter part to find out,
Don't find and replace function as if can meet, can only use VBA?

CodePudding user response:

According to your use case is not remaining lines "participant list"?
Why do you want to delete the red? List all the delete, and then repeated several times to attend

CodePudding user response:

Just as an example, ha,

In fact, to be sure it is not only the participant list that a few words

For example,

,,,,,,, AAA participant list>,,,,,,,,

,,, XXXLL attendance list,,,,


3322 participant list 33111


That I am I want to keep part of the scarlet letter,

CodePudding user response:

refer to the second floor ssson response:
just as an example, ha,

In fact, to be sure it is not only the participant list that a few words

For example,

,,,,,,, AAA participant list>,,,,,,,,

,,, XXXLL attendance list,,,,


3322 participant list 33111


That I am I want to keep the part of the scarlet letter,



1, all the string you want to form an array group (hereinafter referred to as the key words)
2, set pointer, initialization point to document the first character of the
3, take a pointer of one character, to the key words in the group, whether there are consistent with one of the elements of the first character of the keyword
3.1 if you have, then take subsequent characters and key word group match, if subsequent characters can find at least one keyword match completely, keep the keyword, or delete,
3.2 if not, delete the pointer in the characters
4, under the pointer to a character, if not to the end of the document goto 3 or end

CodePudding user response:

Said hiring too, more to the code,
 
Private Sub Command2_Click ()
'need to process the text
Dim strTest As String
StrTest="this is a test string, which contains a number of the need for reserved keywords, want the functions to deal with after all the key words in"

'keywords list, deliberately does not exist in the text of the insert the key words and empty elements, test
Dim aryKey () As String
ReDim aryKey (0 To 3)
AryKey (0)="test"
AryKey (1)="keywords"
AryKey (2)="list"

'the output
The Debug. Print SearchKeys (strTest aryKey)
End Sub

'processing function, input text needs to be checked and keywords list
Private Function SearchKeys (strIn As String, keys () As String) As String
Dim As Long, I j As Long
For I=1 To Len (strIn)
For j=LBound (keys) To UBound (keys)
If the keys (j)=Mid (strIn, I, Len (keys (j))) Then
SearchKeys=SearchKeys & amp; Keys (j)
I=I + Len (keys (j))
DoEvents
End the If
Next
Next
End the Function

CodePudding user response:


Thanks to the teacher first ~
For a while computer experiment,

I'll digested,

CodePudding user response:

Can also use regular expressions:
 Sub test () 
Dim strContent As String
StrContent=ActiveDocument. Content. The Text

Dim reg As Object
The Set reg=CreateObject (" vbscript. Regexp ")

Reg. Global=True
Reg. MultiLine=True
Reg. The ignorecase=True
Reg. The Pattern="(AAA participant list | XXXLL participant list list to attend 33111 | 3333 | 3322 participant list)"

Dim colMatches As Object
The Set colMatches=reg. The Execute (strContent)

Dim strResult As String
StrResult=""

Dim objMatch As Object
For Each objMatch colMatches In
StrResult=strResult & amp; ObjMatch. Value & amp; VbCrLf
Next

MsgBox strResult
End Sub

Run the example:

Download address:
Link: https://pan.baidu.com/s/1xkyedz-9OLXFayN_KEgUzA
The extracted code: wsc0

CodePudding user response:

First cycle + find the red font, using the found=true judgment whether the red font in the array of the content of the selection, and then through the circular array output into a variable
  •  Tags:  
  • VBA
  • Related