Sign in to follow this  
Followers 0
xzaz

String and adding @CRLF

7 posts in this topic

#1 ·  Posted (edited)

Hello guys, happy new scripting year in the first place :)

I got this textfile:

[stop][newline][pos]835234.12341.53452.67363.000000.00[/pos][pos]569834.12341.64389.23673.000000.00[/pos][/newline][config][cl]0.10[/cl][ba]0.30[/b][/config][/stop]

What im doing is getting all the pos numbers out of the file. But now i want to sort it. So it has to come out like this.

[stop]
[newline]
[pos]835234.12341.53452.67363.000000.00[/pos]
[pos]569834.12341.64389.23673.000000.00[/pos]
[/newline]

[config]
[cl]0.10[/cl]
[ba]0.30[/b]
[/config]

[/stop]
It is prob a simple function but cant figure it out. There seem no 'include' function with string.

I was thinking about put everything in a array and then past it with a Return into a editctrl.

Tnx,

xzaz

Edited by xzaz

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

MsgBox (-1,"test title", "This is line - 1" & @CRLF & "This is line - 2" & @CRLF & "This is line - 3")

use this

& @CRLF &

between the lines u want

------------

######## Star2 ########

Edited by star2

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sorry i should explain it bether. the txt that im getting is from a txt file. I read it out with firstline function enc. This is not a static file but dynamic. The data can chance with more points. So is there a way i can detect the end of ']' add a @CRLF and then go further with '[' on the next rule.

Edit: Stringsplit doesn't work cuz it cut off the rule.

Edited by xzaz

Share this post


Link to post
Share on other sites

can u post your script


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <GUIConstants.au3>
#include <Array.au3>
#include <string.au3>
#include <GuiStatusBar.au3>
#include <file.au3>

Global $file = ""
Global $getotherdata = ""
Global $aText[2] = ["File loaded: ","RLPoints: "]
Local $aParts[2] = [150,200]
$mainGUI = GuiCreate("DWGSee editor",300,300)
;StatusBarcreate
$hStatus = _GUICtrlStatusBar_Create ($mainGUI, $aParts, $aText)
;/StatusBarcreate
$getfile = GuiCtrlCreateButton("Get file",(300 - 100)/2,1,100,20)
$sortfilebut = GuiCtrlCreateButton("Sort file",2,254)
GuiCtrlCreateLabel("Begin:",2,25)
GuiCtrlCreateLabel("Eind:",2,45)
$begintxt = GuiCtrlCreateInput("",40,25,200)
$endtxt = GuiCtrlCreateInput("",40,45,200)
$editctrl = GuictrlCreateEdit("",1,65,298,190)
GuiSetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    if $msg = $getfile Then
        $file = FileOpenDialog("Open .mrk file","F:\Kaart zoetermeer","mrk files(*.mrk)")
        FileOpen($file,0)
        Dim $szDrive, $szDir, $szFName, $szExt
        $filename = _PathSplit($file, $szDrive, $szDir, $szFName, $szExt)
        _GUICtrlStatusBar_SetText($hStatus,"File loaded: "&$filename[3]&$filename[4],0)
            getdata(1)
            getdata(2)
    Endif
    if $msg = $sortfilebut Then
        ;Get first RL point
        ;   $begin = $stringtest[0]
            ;Get last RL point
        ;   $max = $stringtest[$maxnumber]
        ;   MsgBox(0,"Informatie","Begin: "&$begin&@CRLF&"Eind: "&$max)
        ;   $datatocopy = "<ATEntitys><ATRedLine><RLPoint>"&$begin&"</RLPoint><RLPoint>"&$max&"</RLPoint><MarkLayoutName>Model</MarkLayoutName></ATRedLine><ATDIMSetting><DIMExtend>0.250</DIMExtend>       <DIMArrowLen>0.500</DIMArrowLen>        <DIMTextHei>1.500</DIMTextHei></ATDIMSetting></ATEntitys>"
            ;Set Data                "<ATEntitys><ATRedLine><RLPoint>          </RLPoint><RLPoint>        </RLPoint><MarkLayoutName>Model</MarkLayoutName></ATRedLine><ATDIMSetting><DIMExtend>0.250</DIMExtend><DIMArrowLen>0.500</DIMArrowLen><DIMTextHei>1.500</DIMTextHei></ATDIMSetting></ATEntitys>
        ;   GuiCtrlSetData($editctrl,$datatocopy)
        ;   FileWrite($file,$datatocopy)
    Endif
Wend

func getdata($nr)
    $line = FileReadLine($file) ;<== Get data from the file chosen
    if $nr = 1 Then ;<== Get all RLPoints and put them in a array
            $stringtest = _StringBetween($line,"<RLPoint>","</RLPoint>")
            GuiCtrlSetData($editctrl,$stringtest)
            $maxnumber = _ArrayMaxIndex($stringtest)
            _GUICtrlStatusBar_SetText($hStatus,"RLPoints: "&$maxnumber,1)
            GuiCtrlSetdata($begintxt,$stringtest[0])
            GuiCtrlSetdata($endtxt,$stringtest[$maxnumber])
    Elseif $nr = 2 Then ;<== Get data and sort it to view it
            GuiCtrlsetData($editctrl,$line)
    Elseif $nr = 3 Then
            GuiCtrlRead($editctrl)
    Endif
Endfunc

Txt file:

http://www.xzaz.nl/helekaart.mrk

Edited by xzaz

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Check this Example

save the following to file [ 001.txt ]

[line one - first][line one - Second][line one - third]

[line two - first][line two - Second][line two - third]

[line three - first][line three - Second][line three - third]

and use this example in the same Dir

#include <String.au3>
#include <array.au3>

$file = FileOpen ("001.txt",0)
$read = FileRead ($file)
$splt = StringSplit ($read , '[' ,1)
;======= this will give you the Number of strings ========
MsgBox (-1, "","Number of Strings is:" & @CRLF & $splt[0])
;=========================================================
$o = _StringBetween ($read , '[',']')

For $i = 0 to $splt[0] - 1 Step 1
MsgBox (-1, "","[" & $o[$i] & "]")
Next
Edited by star2

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

this should do it:

$Text = FileRead("helekaart.txt")
$Split = stringSplit($Text,"<")

$Output = ""
For $i = 1 to $Split[0]
    $NextChar = StringLeft($Split[$i],1)
    If $NextChar = "/" Then
        $Output &= "<"&$Split[$i]
    Else
        $Output &= @CRLF&"<"&$Split[$i]
    EndIf
Next

FileWrite("Output.txt",$Output)

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  
Followers 0