Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

StringSplit?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 )

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Would you mind to stick to a single thread?

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...