How to remove FF or bold up arrow sign from .txt file

Get help with using AutoHotkey and its commands and hotkeys
LiangShuii
Posts: 18
Joined: 29 Sep 2019, 14:34

How to remove FF or bold up arrow sign from .txt file

21 Oct 2019, 05:55

Hi all,

Thank you for your time reading this.

I am following up from a previous post where the user Sir Teddy the First very kindly provided me with this code:

Code: Select all

FileRead, String, result.txt

TextPieces := WordPeriphery(String, "child", 10, 10)

Loop, % TextPieces.Length()
{
    ;MsgBox % TextPieces[A_Index]
    Final := TextPiece[A_Index]
    FileAppend, %Final%, summary.doc
    
}


WordPeriphery(Text, SearchWord, Num1 := 10, Num2 := 10)
{
    if !InStr(Text, SearchWord)
    {
        MsgBox 4096,, Error! Word not found in given String!
        return
    }
   
    Strings := Array()
    StartingPos := 1
    StrReplace(Text, SearchWord,, WordCount)    ; get number of occurrences of the searched word
    
    Loop, %WordCount%
    {
        SearchPattern := "i x S) (\s* \S+){0," Num1 "} \s*" . SearchWord . "[.,?!]* \s* (\S+ \s*){0," Num2 "}"      
        RegExMatch(Text, SearchPattern, Result, StartingPos) ; search for the word at the given starting position (1 for the first word)
        Result := Trim(Result)
        Strings.Push(Result)
        
        StartingPos := InStr(Text, SearchWord,, StartingPos) + 1 ; jump beyond the positon of the last word to get the next
    }
    
    return Strings
}
The code is amazing and extracts all instances of the desired word into a word document however for some reason the word document created with FileAppend has a page break in it. The .txt file version of this word document has a bold upwards pointing arrow and when opening the word document with notepad++ in AINSI there is a black box with FF in it instead of the page break.

Does anyone know how I can remove the page break in word or the FF/Upwards Arrow so that there is no longer this giant gap in the word document.

Cheers,
hd0202
Posts: 144
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: How to remove FF or bold up arrow sign from .txt file

22 Oct 2019, 00:47

Code: Select all

FileRead, String, result.txt
stringreplace, string, string, % chr(12), , all   ; <===
Hubert
LiangShuii
Posts: 18
Joined: 29 Sep 2019, 14:34

Re: How to remove FF or bold up arrow sign from .txt file

22 Oct 2019, 03:23

Hi Hubert

Thank you for your help with this matter,

Unfortunately when I try your code it does not seem to change result.txt

Furthermore, when I try and use:
ReplacedString := stringreplace, string, string, % chr(12), , all
FileAppend, %Replacedstring%, DOESITWORK.doc

I get an error box stating that % is missing a variable in ReplacedString

Cheers,
gregster
Posts: 3379
Joined: 30 Sep 2013, 06:48

Re: How to remove FF or bold up arrow sign from .txt file

23 Oct 2019, 01:14

You can't use a command like this in an expression, in this case, a variable assignment. But you could do this:

Code: Select all

stringreplace, ReplacedString, string, % chr(12), , all
FileAppend, %Replacedstring%, DOESITWORK.txt
ReplacedString is here already the output variable (see the description of the parameters in the StringReplace docs; it is a deprecated command, though)

Well, there is a (recommended) function version of this command nowadays, called StrReplace(). This can be used in expressions like this:

Code: Select all

ReplacedString := StrReplace(string, chr(12))
FileAppend, %Replacedstring%, DOESITWORK.txt
Or combine these two lines into one:

Code: Select all

FileAppend, % StrReplace(string, chr(12)), DOESITWORK.txt	; you can't create a genuine doc-(Word)-file like this, just a text file.
(Again not possible with the StringReplace command)

Return to “Ask For Help”

Who is online

Users browsing this forum: FreakyDoctor, Google [Bot], Xtra and 179 guests