sree161 Posted August 5, 2017 Share Posted August 5, 2017 (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 August 5, 2017 by sree161 to be more specific Link to comment Share on other sites More sharing options...
water Posted August 5, 2017 Share Posted August 5, 2017 StringSplit? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
TheDcoder Posted August 5, 2017 Share Posted August 5, 2017 Or you can do it like this: StringReplace($sParagraph, "Reference Word", @CRLF) EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheSaint Posted August 5, 2017 Share Posted August 5, 2017 (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 August 5, 2017 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) Link to comment Share on other sites More sharing options...
kylomas Posted August 5, 2017 Share Posted August 5, 2017 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 More sharing options...
sree161 Posted August 8, 2017 Author Share Posted August 8, 2017 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 More sharing options...
sree161 Posted August 8, 2017 Author Share Posted August 8, 2017 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 More sharing options...
ripdad Posted August 8, 2017 Share Posted August 8, 2017 (edited) $Split is an array. Insert:at the top of script: #include "array.au3" and view the array like this: _ArrayDisplay($Split) Edited August 8, 2017 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 More sharing options...
sree161 Posted August 8, 2017 Author Share Posted August 8, 2017 #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 More sharing options...
sree161 Posted August 8, 2017 Author Share Posted August 8, 2017 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 Link to comment Share on other sites More sharing options...
Belini Posted August 8, 2017 Share Posted August 8, 2017 (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 August 8, 2017 by Belini My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ Link to comment Share on other sites More sharing options...
TheSaint Posted August 8, 2017 Share Posted August 8, 2017 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) Link to comment Share on other sites More sharing options...
sree161 Posted August 9, 2017 Author Share Posted August 9, 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 New Text Document (2).txt Link to comment Share on other sites More sharing options...
sree161 Posted August 12, 2017 Author Share Posted August 12, 2017 Can someone help me on this plzz?? Link to comment Share on other sites More sharing options...
water Posted August 12, 2017 Share Posted August 12, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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