Jump to content
Sign in to follow this  
Juri

Problem with text

Recommended Posts

Juri

Hello. I need help. I want to remove "<br>" form this text:

Obrońca zwyciężył
Szczęście (z punktu widzenia agresora)
Pech ,
,,,
,Szczęście ,17.0%
Morale: 100%

Agresor:,Jurigag
Pochodzenie:,Myrthana Vengard (671|541) K56
,,,,,,,,,,,,
Ilość: ,0,0,0,0,5,0,0,0,0,0,0,0
Straty: ,0,0,0,0,0,0,0,0,0,0,0,0

Obrońca:,klk*
cel:,klk* (673|537) K56
,,,,,,,,,,,,
Ilość: ,3,0,0,0,0,0,0,0,0,0,0,0
Straty: ,0,0,0,0,0,0,0,0,0,0,0,0

Szpiegostwo
Wyszpiegowane surowce:,nie ma
,Ratusz (Stopień 10)
Koszary (Stopień 2)
Kuźnia (Stopień 5)
Plac (Stopień 1)
Piedestał (Stopień 1)
Rynek (Stopień 1)
Tartak (Stopień 8)
Cegielnia (Stopień 6)
Huta żelaza (Stopień 5)
Zagroda (Stopień 4)
Spichlerz (Stopień 7)
Schowek (Stopień 1)
Mur obronny (Stopień 1)

I want to convert this text to:

Obrońca zwyciężył
Szczęście (z punktu widzenia agresora)
Pech ,
,,,
,Szczęście ,17.0%
Morale: 100%
Agresor:,Jurigag
Pochodzenie:,Myrthana Vengard (671|541) K56
,,,,,,,,,,,,
Ilość: ,0,0,0,0,5,0,0,0,0,0,0,0
Straty: ,0,0,0,0,0,0,0,0,0,0,0,0
Obrońca:,klk*
cel:,klk* (673|537) K56
,,,,,,,,,,,,
Ilość: ,3,0,0,0,0,0,0,0,0,0,0,0
Straty: ,0,0,0,0,0,0,0,0,0,0,0,0
Szpiegostwo
Wyszpiegowane surowce:,nie ma
,Ratusz (Stopień 10)
Koszary (Stopień 2)
Kuźnia (Stopień 5)
Plac (Stopień 1)
Piedestał (Stopień 1)
Rynek (Stopień 1)
Tartak (Stopień 8)
Cegielnia (Stopień 6)
Huta żelaza (Stopień 5)
Zagroda (Stopień 4)
Spichlerz (Stopień 7)
Schowek (Stopień 1)
Mur obronny (Stopień 1)

And, solution this problem must working on more "<br>". Possible?

Edited by Juri

Share this post


Link to post
Share on other sites
omikron48

You can use StringReplace to eliminate all occurances of a certain substring.

Global $string = "She sells seashells by the sea shore."
Global $substring = "she"
StringReplace($string, $subtring, "")

Share this post


Link to post
Share on other sites
Juri

I know this, but i cant replace "breaking the line". I need this to my "analysator" to working on all web viewers ;/

Or this function return number of line without breaking the line:

Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False)
    Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = ""
    If FileExists($sFileName) = 0 Then Return 1
    Do
        $sFile = FileRead($sFileName)
        $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring"

        If $location > 0 Then
            $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "\1"), "(?s)(\v+)", 3) ;Find line number
            $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number

            ;ConsoleWrite("CharPos: " &  $location & "   Ln: " & $iCurrentLineNum & @CRLF)
            $sRes &= $iCurrentLineNum & "|"
            If $bDeleteLine Then
                _FileWriteToLine($sFileName, $iCurrentLineNum, "", 1) ; Remove found line from file.
            Else
                $iOccur += 1
            EndIf
        Else
            ExitLoop
        EndIf
        Sleep(10)
    Until 0
    ;ShellExecute($sFileName)
    Return StringSplit(StringTrimRight($sRes, 1), "|")
EndFunc   ;==>_LineNumsOfSearchStr

I search this function on forum. How to chagne this function to return number of line with breaking the line?

Edited by Juri

Share this post


Link to post
Share on other sites
omikron48

Well, first off, how to you get the text you want to process?

Do you get it as raw text including html tags (like when you view a webpage's source) or do you get it as already formatted text (like when you highlight a webpage and copy/paste the text into a text editor)?

Share this post


Link to post
Share on other sites
Juri

I get this very simple, because application want to work in tray and only open anaylysed file and nothing get from server. I get copy text from Clipget() and stringregexp that text if i want.

Share this post


Link to post
Share on other sites
omikron48

Maybe use StripWS then StringLen to check if a line is empty then skip it?

Share this post


Link to post
Share on other sites
Juri

So, i must read all line and check it ? Hmmm i check this method ;P But i want easier method :idea:

Edited by Juri

Share this post


Link to post
Share on other sites
omikron48

That's one way to do it.

Dunno if there's a better way though, but I'd wager that there probably is.

Edited by omikron48

Share this post


Link to post
Share on other sites
Juri

Yea :idea: I have easy method :)

#include <file.au3>

$file = FileOpen("bk.txt", 0) ; File with breaking line

While 1
    $line = FileReadLine($file)
    if StringLen($line)>0 Then ; Check this is not breaking line
        FileWrite("bk2.txt", $line & @CRLF) ; Save this to new file
    endif
    If @error = -1 Then ExitLoop
WEnd
FileClose($file)

Works perfectly for me :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.