sree161 Posted August 12, 2017 Share Posted August 12, 2017 Hi all, can i get solution for this??? i want to split paragraphs with empty lines as Limiter to split. How can i do this?? StringSplit ( $Read , " " ,$STR_ENTIRESPLIT ) this didn't work and this too didn't work $Sp = StringSplit($Read , @CRLF , 1) any solutions plzz attached reference txt file Spaces between paras are not same....but i have to split them using empty space as limiter Link to comment Share on other sites More sharing options...
mikell Posted August 12, 2017 Share Posted August 12, 2017 I searched a lot but couldn't find the 'attached reference txt file' So this example uses a simple multi-paragraphs string #Include <Array.au3> $txt = "AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting." & _ @crlf & " " & @crlf & @crlf & _ "It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). " & _ @crlf & " " & @crlf & _ "AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying runtimes required! end" Msgbox(0,"", $txt) $res = StringRegExp($txt, '(?s)(.+?)(?:\R\s*\R|$)', 3) _ArrayDisplay($res) Link to comment Share on other sites More sharing options...
sree161 Posted August 14, 2017 Author Share Posted August 14, 2017 (edited) I need to read from a text file and then split the existing text read from the file using empty space as delimiter. Thanks, Sree161 Edited August 14, 2017 by sree161 Link to comment Share on other sites More sharing options...
Trong Posted August 14, 2017 Share Posted August 14, 2017 (edited) I found the attachment:New Text Document (2).txt expandcollapse popup# Name Score 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 1 ssss 10 2 aaaa 20 3 hhhh 30 4 qqqq 40 <5>1 wwww 50 <6>2 ffff 60 <7>3 qqqq 10 <8>4 rrrr 20 <9>5 yyyy 30 <10>6 nnnn 40 <11>7 llll 90 <12>7 iiii 80 Edited August 14, 2017 by VIP post attachment! Regards, Link to comment Share on other sites More sharing options...
kosamja Posted August 14, 2017 Share Posted August 14, 2017 (edited) 17 minutes ago, sree161 said: I need to read from a text file and then split in @mikell example instead of $txt use FileRead(YOUR TXT FILE PATH) Edited August 14, 2017 by kosamja Link to comment Share on other sites More sharing options...
sree161 Posted August 14, 2017 Author Share Posted August 14, 2017 I need to read from a text file and then split the existing text using empty space as delimiter. Thanks, Sree161 Link to comment Share on other sites More sharing options...
mikell Posted August 14, 2017 Share Posted August 14, 2017 Hey man, no need to post the same thing twice, we are not blind kosamja answered. What about a little work from you now ? Link to comment Share on other sites More sharing options...
Trong Posted August 14, 2017 Share Posted August 14, 2017 (edited) for all paragraphs : #include <Array.au3> Global $iFilePath = @ScriptDir & "\New Text Document (2).txt" Global $iFileContent = FileRead($iFilePath) Global $iArrayParagraphs = StringSplit($iFileContent, @CRLF & @CRLF & @CRLF, 1) For $x = 1 To $iArrayParagraphs[0] Local $iArrayLine = StringSplit($iArrayParagraphs[$x], @CRLF, 1) Local $Array3D[UBound($iArrayLine) + 1][3] For $i = 0 To UBound($iArrayLine) - 1 If StringStripWS($iArrayLine[$i], 8) <> "" Then Local $XXX = $iArrayLine[$i] While StringInStr($XXX, " " & " ") $XXX = StringReplace($XXX, " " & " ", " ") WEnd ConsoleWrite($XXX & @CRLF) Local $XNXX = StringSplit($XXX, " ", 2) If UBound($XNXX) > 2 Then $Array3D[$i][0] = $XNXX[0] $Array3D[$i][1] = $XNXX[1] $Array3D[$i][2] = $XNXX[2] EndIf EndIf Next _ArrayDisplay($Array3D) Next for 1 paragraphs : #include <Array.au3> Global $iFilePath = @ScriptDir & "\New Text Document (2).txt" Global $iArrayLine = FileReadToArray($iFilePath) Global $Array3D[UBound($iArrayLine) + 1][3] For $i = 0 To UBound($iArrayLine) - 1 If StringStripWS($iArrayLine[$i], 8) <> "" Then Local $XXX = $iArrayLine[$i] While StringInStr($XXX, " " & " ") $XXX = StringReplace($XXX, " " & " ", " ") WEnd ConsoleWrite($XXX & @CRLF) Local $XNXX = StringSplit($XXX, " ", 2) If UBound($XNXX) > 2 Then $Array3D[$i][0] = $XNXX[0] $Array3D[$i][1] = $XNXX[1] $Array3D[$i][2] = $XNXX[2] EndIf EndIf Next _ArrayDisplay($Array3D) Edited August 14, 2017 by VIP PS: Do not forget to like if your problem is solved sree161 1 Regards, Link to comment Share on other sites More sharing options...
mikell Posted August 14, 2017 Share Posted August 14, 2017 For the fun ... VIP do you like it ? #Include <Array.au3> $txt = FileRead(@ScriptDir & "\New Text Document (2).txt") $res = StringRegExp($txt, '(?m)^<?(\d+)>?\d?\h+(\S+)\h+(\d+)\h*$', 3) Local $n = UBound($res), $k = 3, $res2D[Ceiling($n/$k)][$k] For $i = 0 To $n - 1 $res2D[Int($i / $k)][Mod($i, $k)] = $res[$i] Next _ArrayDisplay($res2D) Trong 1 Link to comment Share on other sites More sharing options...
sree161 Posted August 21, 2017 Author Share Posted August 21, 2017 On 8/14/2017 at 8:53 PM, VIP said: for all paragraphs : #include <Array.au3> Global $iFilePath = @ScriptDir & "\New Text Document (2).txt" Global $iFileContent = FileRead($iFilePath) Global $iArrayParagraphs = StringSplit($iFileContent, @CRLF & @CRLF & @CRLF, 1) For $x = 1 To $iArrayParagraphs[0] Local $iArrayLine = StringSplit($iArrayParagraphs[$x], @CRLF, 1) Local $Array3D[UBound($iArrayLine) + 1][3] For $i = 0 To UBound($iArrayLine) - 1 If StringStripWS($iArrayLine[$i], 8) <> "" Then Local $XXX = $iArrayLine[$i] While StringInStr($XXX, " " & " ") $XXX = StringReplace($XXX, " " & " ", " ") WEnd ConsoleWrite($XXX & @CRLF) Local $XNXX = StringSplit($XXX, " ", 2) If UBound($XNXX) > 2 Then $Array3D[$i][0] = $XNXX[0] $Array3D[$i][1] = $XNXX[1] $Array3D[$i][2] = $XNXX[2] EndIf EndIf Next _ArrayDisplay($Array3D) Next for 1 paragraphs : #include <Array.au3> Global $iFilePath = @ScriptDir & "\New Text Document (2).txt" Global $iArrayLine = FileReadToArray($iFilePath) Global $Array3D[UBound($iArrayLine) + 1][3] For $i = 0 To UBound($iArrayLine) - 1 If StringStripWS($iArrayLine[$i], 8) <> "" Then Local $XXX = $iArrayLine[$i] While StringInStr($XXX, " " & " ") $XXX = StringReplace($XXX, " " & " ", " ") WEnd ConsoleWrite($XXX & @CRLF) Local $XNXX = StringSplit($XXX, " ", 2) If UBound($XNXX) > 2 Then $Array3D[$i][0] = $XNXX[0] $Array3D[$i][1] = $XNXX[1] $Array3D[$i][2] = $XNXX[2] EndIf EndIf Next _ArrayDisplay($Array3D) Can u help me in understanding the logic behind it?? I am unable to get any output?? Link to comment Share on other sites More sharing options...
sree161 Posted August 21, 2017 Author Share Posted August 21, 2017 On 8/15/2017 at 1:24 AM, mikell said: For the fun ... VIP do you like it ? #Include <Array.au3> $txt = FileRead(@ScriptDir & "\New Text Document (2).txt") $res = StringRegExp($txt, '(?m)^<?(\d+)>?\d?\h+(\S+)\h+(\d+)\h*$', 3) Local $n = UBound($res), $k = 3, $res2D[Ceiling($n/$k)][$k] For $i = 0 To $n - 1 $res2D[Int($i / $k)][Mod($i, $k)] = $res[$i] Next _ArrayDisplay($res2D) can u help me understand the logic behind it?? Link to comment Share on other sites More sharing options...
mikell Posted August 21, 2017 Share Posted August 21, 2017 5 hours ago, sree161 said: can u help me understand the logic behind it?? Sorry. Here is the logic : My script assumes that the 3 things you want to get in each line are : number, name, score Meaning, in this line "4 qqqq 40", get "4, qqqq, 40" and in this one : "<5>1 wwww 50", get "5, wwww, 50" So I used a regular expression to parse each concerned line, get the wanted parts and store them in a 1D array ($res) The For/Next loop after is used to order the parts nicely by building a 2D array ($res2D) with a row per line and 3 columns sree161 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now