sree161

is it possible to spit a big pagagraph into 2 paragrapghs???

15 posts in this topic

#1 ·  Posted (edited)

i have some text in notepad (almost 5 paragraphs). i need to divide each paragraph into 2 using some reference letter for further processing.
is it possible ??

is yes....can i know the command to split??

Edited by sree161
to be more specific

Share this post


Link to post
Share on other sites



#2 ·  Posted

StringSplit?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Or you can do it like this:

StringReplace($sParagraph, "Reference Word", @CRLF)

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

3 hours ago, sree161 said:

is it possible ??

Anything is possible, but it depends on how tricky you want to get and what you are using it for .... ultimate aim etc.

StringSplit as has been mentioned, is a good starting point ... StringReplace too.

However, would you like a fairly even split? Do you want to preserve sentences or words?

StringLen could also be helpful, divided by 2 and using the Round (or related) commands. StringInstr is another useful command.

And of course you can combine a bunch of those commands above together.

If you are having trouble, give us an example of the sort of text (paragraphs)  you want to split, and we can provide coded solutions for you. We also like it if you show the code you have tried.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#5 ·  Posted

Quote

If you are having trouble, give us an example of the sort of text (paragraphs)  you want to split

and the char you want to split on.  If you gave us more on your overall project we may have some suggestions.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#6 ·  Posted

On 8/6/2017 at 3:51 AM, kylomas said:

and the char you want to split on.  If you gave us more on your overall project we may have some suggestions.

kylomas

Hi all,

i have a text document which has 5 paras as given below. Attached sample text file for reference,
 

#   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

the above para needs to be divided into two paras 1) without "<>" 2) with "<>"
so post split it should be like
para1:
1   ssss   10
2   aaaa   20
3   hhhh   30
4   qqqq   40

Para2:
<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

Again in these paras i need to perform serach operations.
So here "<" should be the char which needs to be used to split on.
Before all these i need the divide all these 5 paras usng  "    " (Empty split).
in this i have to select  "#" of specific people who's score is >=60 which is further part of my project.
 

Now my doubts are
1) Is it good to use autoit for my requirement??
if no can u suggest any other scripting language??
I am using autoit because i found it as best to use for notepad automation on google.
i possible will post some of my code which wrote.

Thanks in advance,
Sree161.
 

New Text Document (2).txt

Share this post


Link to post
Share on other sites

#7 ·  Posted

Hi all,

i tried the below script and got empty output. can i know where i went wrong???

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

$File = "C:\Users\location\sample.txt"
$Open = FileOpen($File, 0)
$Read = FileRead($Open)
$Split = StringSplit ( $Read , "<" ,$STR_ENTIRESPLIT)
MsgBox ( $MB_OK, "Output", $Split )

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

$Split is an array.

Insert:at the top of script:
#include "array.au3"

and view the array like this:
_ArrayDisplay($Split)

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

#9 ·  Posted

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

$File = "C:\Users\dsreekan\Desktop\P2\OTA3058\sample.txt"
$Open = FileOpen($File, 0)
$Read = FileRead($Open)

$Sp = StringSplit ( $Read , "<6>" ,$STR_ENTIRESPLIT )
For $i = 1 To $Sp[0]
MsgBox ( $MB_SYSTEMMODAL, "Output", "$Sp[" & $i & "] - " & $Sp[$i] )
Next

 

i did in this way and got the output right.  

Share this post


Link to post
Share on other sites

#10 ·  Posted

i want to split paragraphs with empty lines as character to split.
How can i do this??

StringSplit ( $Read , "      " ,$STR_ENTIRESPLIT )

this didn't work

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

If it is to stay as in the example you posted can use so:

#include <File.au3>

$file = @ScriptDir & "\TEST.txt"
$lines = _FileCountLines($file)
If $lines > 0 Then
    For $i = 1 To $lines
        $read = FileReadLine($file, $i)
        If StringInStr($read, "<") Then
            _FileWriteToLine($file, $i, " ", 0)
            ExitLoop
        EndIf
    Next
EndIf

or like this

$file = @ScriptDir & "\TEST.txt"
$read = FileRead($file)
If StringInStr($read, "<") Then
    FileDelete($file)
    FileWrite($file, StringReplace($read, "<", @CRLF & "<", 1))
EndIf

 

Edited by Belini

Share this post


Link to post
Share on other sites

#12 ·  Posted

If each of your lines has a carriage return or line feed, you would probably be better splitting on that character.

i.e. the following will do that automatically.

$array = FileReadToArray($File)

or do your FileOpen and FileRead and then use something like the following with that.

$Sp = StringSplit($Read , @CRLF , 1)

From there you can use more StringSplit and or StringInstr commands inside of loops ... or even RegEx etc.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#13 ·  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

New Text Document (2).txt

Share this post


Link to post
Share on other sites

#14 ·  Posted

Can someone help me on this plzz??

Share this post


Link to post
Share on other sites

#15 ·  Posted

Would you mind to stick to a single thread?

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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