sree161

How to split text file having paras using empty lines as limiter

9 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

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)

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by sree161

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I found the attachment:
New Text Document (2).txt

#   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 by VIP
post attachment!

Regards,
 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by kosamja

Share this post


Link to post
Share on other sites

I need to read from a text file and then split the existing text using empty space as delimiter.

Thanks,

Sree161

Share this post


Link to post
Share on other sites

Hey man, no need to post the same thing twice, we are not blind

kosamja answered. What about a little work from you now ?   :yes:

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by VIP
PS: Do not forget to like if your problem is solved 
1 person likes this

Regards,
 

Share this post


Link to post
Share on other sites

For the fun ... VIP do you like it ?  :D

#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)

 

1 person likes this

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